blog.Ring.idv.tw

用Zend_Http做一個IP地理位址查詢

用Zend_Http做一個IP地理位址查詢


剛剛玩了一下「IP地址查询-IP地理位置查询系统-中文e讯」想說乾脆也用Zend_Http來做一個應用~

require_once 'Zend/Http/Client.php';

$ip = '163.17.131.33';

$url = "http://ip.cemsg.com/index.php";

$client = new Zend_Http_Client();
$client->setUri($url);
$client->setConfig(array(
    'maxredirects' => 0,
    'timeout'      => 30)
);
$client->setMethod(Zend_Http_Client::POST);
$client->setParameterPost('s', $ip);
$client->setParameterPost('doit', 1);
$client->setHeaders('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)');

$response = $client->request();

if ($response->isError())
{
 	echo "Error transmitting data.\n";
	echo "Server reply was: " . $response->getStatus() . " " . $response->getMessage() . "\n";
}else{
	$body = $response->getBody();
	$pattern = "/<div id=\"ip_pos\" style=\"color:#FF0000\">(.*)<\/div>/Us";
	preg_match($pattern, $body, $matches);
	echo $matches[1];
}

不過出來的結果好像似乎有點不準,上述的IP是學校的Web Server,但回傳給我的字串為何顯示「澳大利亚米尔顿」呵~ 不過有些還蠻準確的~

2007-12-08 21:41:21

2 comments on "用Zend_Http做一個IP地理位址查詢"

  1. 1. sno 說:

    可以幫我查查
    218.171.116.161
    218.171.110.207
    這兩個IP的地理位置嗎
    謝謝

    2008-08-06 18:16:26

  2. 2. Shen 說:

    上述網址(http://ip.cemsg.com/index.php)就可以查了喲~
    你提到的這兩個IP區段屬於中華電信的~

    2008-08-06 18:24:41

Leave a Comment

Copyright (C) Ching-Shen Chen. All rights reserved.

::: 搜尋 :::

::: 分類 :::

::: Ads :::

::: 最新文章 :::

::: 最新回應 :::

::: 訂閱 :::

Atom feed
Atom Comment