我试图纠正拉姆库马尔的答案,但每当我编辑他们的帖子,我将被暂时禁止,我的修改被忽略。(至于为什么,我不知道,这是我第一次也是唯一一次在这个网站上编辑。)
由于网站更改和管理员执行基本的bot检查(检查标题),他的代码不再工作:
$IP = $_SERVER['REMOTE_ADDR'];
$User_Agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0';
$Accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$Accept_Language = 'en-US,en;q=0.5';
$Referer = 'http://whatismyipaddress.com/';
$Connection = 'keep-alive';
$HTML = file_get_contents("http://whatismyipaddress.com/ip/$IP", false, stream_context_create(array('http' => array('method' => 'GET', 'header' => "User-Agent: $User_Agent\r\nAccept: $Accept\r\nAccept-Language: $Accept_Language\r\nReferer: $Referer\r\nConnection: $Connection\r\n\r\n"))));
preg_match_all('/
(.*?)(.*?)/s', $HTML, $Matches, PREG_SET_ORDER);$ISP = $Matches[3][2];
$City = $Matches[11][2];
$State = $Matches[10][2];
$ZIP = $Matches[15][2];
$Country = $Matches[9][2];
?>
ISP : | <?php echo $ISP;?> |
City : | <?php echo $City;?> |
State : | <?php echo $State;?> |
Zipcode : | <?php echo $ZIP;?> |
Country : | <?php echo $Country;?> |