function parseValue($val, $str){ preg_match("/$val\:\s+(.*?)\n/si", $str, $ret); return $ret[1]; } function getOperator($ip){ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, 'http://www.ripn.net/nic/whois/whois.cgi'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, array( "Whois" => $ip, "Host" => "whois.ripe.net" )); $res = curl_exec($ch); preg_match('/
(.*)<\/pre>/si', $res, $res2); $res2 = strtolower($res2[1]); $country = parseValue('country', $res2); $descr = parseValue('descr', $res2); $name = parseValue('netname', $res2); $operator = $country; if($country == 'ru' && (preg_match('/megafon/', $name) || preg_match('/megafon/', $descr)) $operator = 'ru_megafon'; return $country.' | '.$descr.' | '.$name.' | '.$operator; } echo getOperator(isset($_GET['ip']) ? $_GET['ip'] : $_SERVER['REMOTE_ADDR']); ?>