我想查询这些IP块,我已经将这些块卷曲/解析/修剪/插入到服务器上的一个mysql数据库表中:
- [ftp://ftp.arin.net/pub/stats/ripencc/delegated-ripencc-latest](ftp://ftp.arin.net/pub/stats/ripencc/delegated-ripencc-latest)
- [ftp://ftp.arin.net/pub/stats/lacnic/delegated-lacnic-latest](ftp://ftp.arin.net/pub/stats/lacnic/delegated-lacnic-latest)
- [ftp://ftp.arin.net/pub/stats/arin/delegated-arin-latest](ftp://ftp.arin.net/pub/stats/arin/delegated-arin-latest)
- [ftp://ftp.arin.net/pub/stats/apnic/delegated-apnic-latest](ftp://ftp.arin.net/pub/stats/apnic/delegated-apnic-latest)
- [ftp://ftp.arin.net/pub/stats/afrinic/delegated-afrinic-latest](ftp://ftp.arin.net/pub/stats/afrinic/delegated-afrinic-latest)
规范(和表列结构):
registry|cc|type|start|value|date|status
问题)如何输入单个IP地址,并返回一个2字符的ISO 3166国家代码?。
我试着写了这方面的查询。但我并不真正理解什么是“启动”means...or,至少如何将其与IP块范围的某种"end“关联起来。
在过去,我曾针对高/低或从/到范围查询IP地址的长形式。
如果这一点有帮助的话,我有以下php函数,我过去曾使用这些函数将IP地址转换为长形式整数:
//Convert IPv6 address into long form number
function ip6_to_ipnumber($ip_address) {
$pton = @inet_pton($ip_address);
if (!$pton) { return false; }
$number = '';
foreach (unpack('C*', $pton) as $byte) {
$number .= str_pad(decbin($byte), 8, '0', STR_PAD_LEFT);
}
return base_convert(ltrim($number, '0'), 2, 10);
}
//Convert IPv4 address into long form number
function ip4_to_ipnumber($ip_address) {
return ip2long($ip_address);
}
//Identify the IP address version
function ip_version($ip_address) {
return strpos($ip_address, ":") === false ? 4 : 6;
}让我接受赏金:
本质上,我正在寻找一种解决方案,根据来自区域注册中心的最新公共域IP块数据来定位ip地址国。
这个解决方案可能会对很多人有用。祝你好运,谢谢你们的帮助!
发布于 2016-01-05 14:57:19
嗨,我正在研究你的问题,我发送电子邮件,以获得信息,但这些服务的工厂没有支持这一点。但是,如果您可以查看链接,则页是一个远程文件(name_file.text),如果您可以使用该文件,请使用
$content = file_get_contents('http://www.example.com/');
echo $content;如果您尝试这样做,您可以读取url (远程文件)。
有关此链接的更多信息,请查看此链接。
在这里输入链接描述
您可以获得更多关于读取文件的每个部分的信息,并使用您需要的方式。
file() - Reads entire file into an array
fgets() - Gets line from file pointer
fread() - Binary-safe file read
readfile() - Outputs a file
file_put_contents() - Write a string to a file
stream_get_contents() - Reads remainder of a stream into a string
stream_context_create() - Creates a stream context
$http_response_headerhttps://stackoverflow.com/questions/34594160
复制相似问题