Jump to content

An Application of the checkdnsrr() Function


iwato
 Share

Recommended Posts

BACKGROUND: The following code takes an ordinary domain name, reverses it, concatenates it to another domain name via a dot, and performs a domain name record check. Apparently it is suppose to tell you whether or not a particular IP address has been black-listed. PROBLEM: What I find troubling is the length of time that it takes to process the code -- more than a half-minute. As I am hardly familiar with blacklisting, I am hoping that someone can explain the very long delay.

<?php	function check_dnsbl($ip) {		$dnsbl_check=array("bl.spamcop.net","list.dsbl.org",			"sbl.spamhaus.org",'xbl.spamhaus.org');		if($ip){			$rip=implode('.',array_reverse(explode(".",$ip)));			foreach($dnsbl_check as $val){				if(checkdnsrr($rip.'.'.$val.'.','A'))					return $rip.'.'.$val;			}		}		return false;	}?>

Roddy

Link to comment
Share on other sites

If you want to avoid the delay, you'd have to build a custom DNS cache - a list of IPs residing locally that you check before resolving the domains and updating the IP list regularly, or better yet, use dns_get_record(), keep the TTL and refresh the cache based on it (like real DNS caches do). Why doesn't PHP have a built in DNS cache is beyond me.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...