How to retrieve the IPv4 address ranges allocated to Hong Kong?
2006-06-06Since tom.com days, I have always wondered how Leon managed to get all of the IP ranges assigned to Hong Kong. Certainly, the utter crap HKDNR won’t provide this kind of listing. The mystery is keeping me puzzled for all these years.
Finally, I just get it today after searching through APNIC. Basically it’s just one command (wrapped because it’s too long):
wget -q -O - http://ftp.apnic.net/stats/apnic/delegated-apnic-latest | grep '^apnic|HK|ipv4' | awk -F\| 'BEGIN{OFMT="%d"; for (i=0; i<32; i++) {power[32-i]=2^i}} {for (k in power) {if ($5 == power[k]) print $4 “/” k}}’
To retrieve IPv4 address allocation for other districts, use capitalized ISO 3166 code of that district to replace ‘HK’. For example, ‘CN’ for China and ‘TW’ for Taiwan.
2006-06-07 03:41 update: Alan Tam made a good suggestion to make it simpler. Please read the comment.









