php查询ip地址来源归属地的脚本

 <?php
header('Content-Type:text/html;charset=utf-8'); if($_GET['sub']){
$ip = $_GET['ip'];
$msg = '';
ipSearch();
} function ipSearch(){
global $ip,$msg;
if(!$ip){
$msg = '请至少填写一个ip!';
return;
}
$arises = substr_count($ip,'.');
$long = ip2long($ip);
if($arises != 3 || $long == false || $long== -1){
$msg = '无效ip地址,请重新输入!';
return;
}
$content = file_get_contents('http://www.ip138.com/ips1388.asp?action=2&ip='.$ip);
$content = iconv('gb2312', 'utf-8', $content);
$pos = stripos($content, '<li>本站主数据');
if(!$pos){
$msg = '没有查询到!';
return;
}
$endPos = stripos($content, '</li>', $pos);
$jumpLen = strlen('<li>本站主数据:');
$address = substr($content, $pos+$jumpLen, $endPos-$pos-$jumpLen);
$msg = $address;
return;
} ?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
<form method="get">
<input type="text" name="ip" />
<input type="submit" value="search" name="sub" />
</form><br />
<?php echo $msg; ?>
</body>
</html>
上一篇:Linux内核分析第三周学习笔记


下一篇:(1)ActivityThread分析