Question

I have started working on the spam filtering in email for which i need to write a module which would query the DNS for blasklisted IP's. As a beginner can any please suggest me a good reading about DNS and making query to it using C++? . I searched around but wasn't able to get a very good source. Thanks in advance

Was it helpful?

Solution

As a beginner, you basically should know about one function, gethostbyname.

Then if you want to check 8.8.4.4 against zen.spamhaus.org, call

gethostbyname ("4.4.8.8.zen.spamhaus.org")

(note the reversed octets).

If this returns non-NULL, the IP is listed.

Now this is very primitive method with a number of drawbacks, but it works and you should try it before you move on to more sophisticated methods.

OTHER TIPS

Be very careful. DNS has been a very fruitful place for exploitable code. It's remarkably easy to write vulnerable DNS software.

Most of the time you'll want to use an asynchronous resolver so that a slow or non-responsive DNS server cannot stall your application indefinitely. You just want it to stall delivery of a single specific mail. There's a handful of libraries packaged for Ubuntu:

libadns1-dev - Asynchronous-capable DNS client library and utilities
libc-ares-dev - library for asyncronous name resolves (development files)
libc-ares2 - library for asyncronous name resolves
firedns - Runtime binaries for firedns, an asynch. dns resolver library
libares-dev - asynchronous dns resolver library
libares0 - asynchronous dns resolver library
libfiredns-dev - Development files for firedns, an asynch. dns resolver library
libfiredns0.9 - Runtime libraries for firedns, an asynch. dns resolver library
libfiredns-dev - Development files for firedns, an asynch. dns resolver library
libfiredns0.9 - Runtime libraries for firedns, an asynch. dns resolver library
libowfat-dev - A reimplementation of libdjb
libudns-dev - async-capable DNS stub resolver library, development files

I've never used any of these so I can't give recommendations here. Sorry.

You might want to run a local recursive resolver to cache the results of lookups. This can reduce the amount of intelligence you have to program and allow your software to be significantly simpler. I have used the pdns-recursor before and loved it. Fantastic tool.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top