public static function isPrivateIP($ip) { if (!_IpAddresses::isIPAddress($ip)) { return false; } $slash8 = _IpAddresses::checkIpToNetwork($ip, '255.0.0.0'); if ($slash8 == '10.0.0.0' || $slash8 == '127.0.0.0') { return true; } $slash12 = _IpAddresses::checkIpToNetwork($ip, '255.240.0.0'); if ($slash12 == '172.16.0.0') { return true; } $slash16 = _IpAddresses::checkIpToNetwork($ip, '255.255.0.0'); if ($slash16 == '169.254.0.0' || $slash16 == '192.168.0.0') { return true; } return false; }
public static function lookupHostDNS($host) { if (_IpAddresses::isIPAddress($host)) { return _IpAddresses::getHostByIp($host); } else { $host = escapeshellarg($host); exec('host -t a -W 2 ' . $host, $output, $return); if ($return !== 0) { return ''; } else { $output = implode($output); $ips = _IpAddresses::getAllIPsFromString($output, true); $ir = ""; foreach ($ips as $ip) { $ir .= "{$ip},"; } return trim($ir, ','); } /* if(strripos($host,'not found')!==false) return false; if(strripos($host,'SERVFAIL')!==false) return false; $phost = trim(end(explode(' ', $host))); if(strripos($phost,'reached')!==false) return false; return $phost; */ } }