我正在尝试获取分配给某个国家/地区的IPv4范围的最新列表。
我使用http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest获取列表,然后按国家/地区扩展名筛选。
我们来拿中国吧。 curl 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | grep ipv4 | grep CN | awk -F\| '{ printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > chnroute.txt curl 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | grep ipv4 | grep CN | awk -F\| '{ printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > chnroute.txt给我们提供了IPv4的列表,如果我没有弄错的话。 到现在为止还挺好。
但是这个列表中似乎没有一些IP范围。
为了这个例子,我们把重点放在106.0.0.0/8范围。
我们可以知道整个范围是从这个页面分配给亚太地区https://www.apnic.net/publications/research-and-insights/apnic-resource-range
摘录: APNIC allocates resources in the following ranges within the Asia Pacific region: ... 106.0.0.0/8 ...
在线查看列表( http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest ),我们可以看到: apnic|TW|ipv4|106.1.0.0|65536|20110323|allocated apnic|CN|ipv4|106.2.0.0|131072|20110321|allocated apnic|CN|ipv4|106.4.0.0|262144|20110321|allocated OK,但106.3.0.0怎么106.3.0.0 ?
APNIC Whois可以给我们答案: https://wq.apnic.net/whois-search/static/search.html?query=106.3.0.0/24 : https://wq.apnic.net/whois-search/static/search.html?query=106.3.0.0/24
摘录: inetnum: 106.3.0.0 - 106.3.127.255 netname: CNISP-UNION descr: CNISP-Union Technology (Beijing) Co., Ltd Oups,这似乎也属于中国。
那为什么不列在http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest ? 看ftp://ftp.apnic.net/apnic/stats/apnic/可以find一些其他资源,但似乎没有更完整的东西。
我怎么理解这个? 我是否需要了解此文件中列出的ASN信息以获取完整列表?
从RIR统计交换格式
4.3 Record format ... Format: registry|cc|type|start|value|date|status[|extensions...] ... start In the case of records of type 'ipv4' or 'ipv6' this is the IPv4 or IPv6 'first address' of the range. ... value In the case of IPv4 address the count of hosts for this range. This count does not have to represent a CIDR range.
正如你所看到的,这个分配apnic|CN|ipv4|106.2.0.0|131072|20110321|allocated的主机数是131072,这是(2 ^ 16) * 2 ,并且因为106.2.0.0是第一个地址范围,这个分配包括106.2.0.0/16和106.3.0.0/16