Skip to content

impliedchaos/ip-alloc

Repository files navigation

ip-alloc

Build

You can view the generated data at this link. It is generated daily.

I needed a count of IP addresses allocated by country. Wikipedia has this page, but it's out of date.

So I made this instead.

Sources

RIPE NCC has several IP assignments listing the country as "EU". So the statistics for RIPE NCC is preprocessed and the country for those subnets is attempted to be discerned with a whois query. This works in several cases but in others it doesn't, so "Europe" can sometimes show up as a nation in the listing.

IP Address Counting

IPv4 addresses are counted by adding the size of each block minus 2. This is to account for the ones and zeroes broadcast addresses of the subnetwork not being assignable. Network blocks with a length that isn't a power of two have another 2 addresses subtracted since it will take at least two subnetworks for the block. This does not account for all the other subnetting done to the blocks by their owners (which further reduces useable address space).

The IPv6 address space is enormous. The counts are astronomical and kind of silly, but I added it for completeness.

Other Stuff

Since we're going through the trouble of parsing the RIR delegation stats every night, this project also creates the GeoIP-whois.dat file that can be used to determine the correct whois server for an IP (for those of us that do automated whois queries). The following countries in the file should be mapped to the corresponding whois server:

  • AP, Asia/Pacific Region - whois.apnic.net
  • EU, Europe - whois.ripe.net
  • MX, Mexico - whois.lacnic.net
  • O1, Other - whois.iana.org
  • US, United States - whois.arin.net
  • ZA, South Africa - whois.afrinic.net

Example usage:

$ geoiplookup -f ./GeoIP-whois.dat 0.0.0.1
GeoIP Country Edition: O1, Other
$ whois -h whois.iana.org 0.0.0.1
...
$ geoiplookup -f ./GeoIP-whois.dat 1.0.0.1
GeoIP Country Edition: AP, Asia/Pacific Region
$ whois -h whois.apnic.net 1.0.0.1
...
$ geoiplookup -f ./GeoIP-whois.dat 2.0.0.1
GeoIP Country Edition: EU, Europe
$ whois -h whois.ripe.net 2.0.0.1
...
$ geoiplookup -f ./GeoIP-whois.dat 3.0.0.1
GeoIP Country Edition: US, United States
$ whois -h whois.arin.net 3.0.0.1
...
$ geoiplookup -f ./GeoIP-whois.dat 41.0.0.1
GeoIP Country Edition: ZA, South Africa
$ whois -h whois.afrinic.net 41.0.0.1
...
$ geoiplookup -f ./GeoIP-whois.dat 177.0.0.1
GeoIP Country Edition: MX, Mexico
$ whois -h whois.lacnic.net 177.0.0.1
...

You can schedule nightly downloads of the file by accessing it here: https://github.com/impliedchaos/ip-alloc/raw/main/GeoIP-whois.dat

Author: Dave Maez

About

IP address allocation by country.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •