Min*_*int 17 whois geolocation dreamhost
在你说这是重复之前继续阅读,但事实并非如此.(据我所见)
我想从客户端获取php中的县代码.
是的我知道你可以使用外部网站或"geoip_record_by_name"这样做,但我不想依赖外部网站,我不能使用shard Dreamhost托管为php安装"pear".
我以为我可以这样做:
$output = shell_exec('whois '.$ip.' -H | grep country | awk \'{print $2}\'');
echo "<pre>$output</pre>";
Run Code Online (Sandbox Code Playgroud)
但是dreamhost似乎有一个旧版本的whois(4.7.5),所以我在分配的IP上得到了这个错误:
Unknown AS number or IP network. Please upgrade this program.
Run Code Online (Sandbox Code Playgroud)
因此,除非有人知道如何将一个较新版本的whois的二进制文件放到dreamhost上.
或者是否有另一种方法可以从正在加载页面的客户端获取国家/地区代码?
Jed*_*els 27
Whois只是whois服务的客户端,所以从技术上讲,你仍然依赖于外部网站.对于失败的查询,您可以尝试回退到查询的另一个站点,例如hostip.info,碰巧有一个不错的API并且看起来很友好:
http://api.hostip.info/country.php?ip=4.2.2.2
Run Code Online (Sandbox Code Playgroud)
回报
US
Run Code Online (Sandbox Code Playgroud)
祝好运,
--jed
编辑:@Mint以下是hostip.info上API的链接:http://www.hostip.info/use.html
Dal*_*dal 18
MaxMind提供免费的PHP GeoIP国家查找课程(还有一个免费的国家/城市查找课程).
你想要的位是"纯PHP模块"中提到的.这不需要您安装任何东西,也不需要依赖它们,也不需要安装任何特殊的PHP模块.只需将GeoIP数据文件保存在某处,然后使用其提供的类与其进行交互.