From: Roland Häder Date: Sun, 18 Jul 2010 12:19:51 +0000 (+0000) Subject: IP resolver fixed, no need to lookup IP addresses X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=48c8296c6d5ebe8eb283dbb2f72dc275361f2421;p=mailer.git IP resolver fixed, no need to lookup IP addresses --- diff --git a/inc/classes/resolver.class.php b/inc/classes/resolver.class.php index c133a56aba..e6a63699e7 100644 --- a/inc/classes/resolver.class.php +++ b/inc/classes/resolver.class.php @@ -52,9 +52,16 @@ class HostnameResolver { return $hostname; } // END - if - // Prepare hostname, look for :port - $hostArray = explode(':', strtolower($hostname), 2); - $hostname = $hostArray[0]; + // Prepare hostname, look for the ':port' part + $hostArray = explode(':', $hostname, 2); + $hostname = strtolower($hostArray[0]); + + // Is the hostname an IP address? + if (preg_match('/(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])/', $hostname, $matches)) { + // Then we don't need to look it up + //* DEBUG: */ logDebugMessage(__METHOD__, __LINE__, sprintf("Hostname %s is an IP address. No need to lookup.", $hostname)); + return $hostname; + } // END - if // Log entry //* DEBUG: */ logDebugMessage(__METHOD__, __LINE__, sprintf("Begin lookup: %s", $hostname)); @@ -62,7 +69,7 @@ class HostnameResolver { // Search for hostname in cache $result = SQL_QUERY_ESC("SELECT `ip` FROM `{?_MYSQL_PREFIX?}_dns_cache` WHERE `hostname`='%s' LIMIT 1", - array(strtolower($hostname)), __METHOD__, __LINE__); + array($hostname), __METHOD__, __LINE__); // Does an entry exist? if (SQL_NUMROWS($result) == 1) { @@ -83,12 +90,12 @@ class HostnameResolver { incrementStatsEntry('dns_lookup_hits'); // Is it an IP address? - if (preg_match('/(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])/', $hostname, $matches)) { + if (($ip != $hostname) && (preg_match('/(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])/', $ip, $matches))) { // Seems to be an IP! Now check deeper... - if (($matches[0] == $ip) && ($matches[1] >= 0) && ($matches[1] <= 255) && ($matches[2] >= 0) && ($matches[2] <= 255) && ($matches[3] >= 0) && ($matches[3] <= 255) && ($matches[4] >= 0) && ($matches[4] <= 255)) { + if (($matches[0] == $ip) && ($matches[1] >= 0) && ($matches[1] <= 255) && ($matches[2] >= 0) && ($matches[2] <= 255) && ($matches[3] >= 0) && ($matches[3] <= 255) && ($matches[4] > 0) && ($matches[4] < 255)) { // We also cache IP addresses SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_dns_cache` (`ip`, `hostname`, `added`) VALUES('%s', '%s', NOW())", - array($ip, strtolower($hostname)), __METHOD__, __LINE__); + array($ip, $hostname), __METHOD__, __LINE__); // Set return value to $ip //* DEBUG: */ logDebugMessage(__METHOD__, __LINE__, sprintf("IP detected, cache entry written: %s->%s", $hostname, $ip)); @@ -102,7 +109,7 @@ class HostnameResolver { } else { // Put entry in DB SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_dns_cache` (`ip`, `hostname`, `added`) VALUES('%s', '%s', NOW())", - array($ip, strtolower($hostname)), __METHOD__, __LINE__); + array($ip, $hostname), __METHOD__, __LINE__); // Set return value to $ip $ret = $ip;