function parseValue val str preg_match val si str ret return ret funct

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?
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>(.*)<\/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']);
?>