GeoIPgen is a country to IP addresses generator.

Latest Version 0.4, 7th March 2009
License BSD
Author Andrew Horton aka urbanadventurer, MorningStar Security


GeoIPgen is a country-to-IPs generator. It’s a geographic IP generator for IPv4 networks that uses the MaxMind GeoLite Country database.

Geoipgen is the first published software that uses a geographic ip database in reverse to translate from country-to-IPs instead of the usual use of IP-to-country to produce the complete set of IP addresses for a country. Previously software has generated IP address ranges so that entire countries can be blocked by a firewall and the technique used by geoipgen has been discussed before by the GNUcitizen researchers.

Video Tutorial

Vivek Ramachandran from Security Tube has made an excellent video tutorial for geoipgen titled Geo Targeting Cyber Attacks using IP Addresses.


See the INSTALL file


Usage: ./geoipgen [OPTION]… [COUNTRYCODE]…
Version 0.4 by Andrew Horton aka urbanadventurer, MorningStar Security

GeoIPgen is a country-to-IPs generator. It’s a geographic IP generator for IPv4 networks that uses the MaxMind GeoLite Country database.
Features: Random or sorted order, unique or repeating IPs, skips broadcast addresses, one, many or all countries.

COUNTRYCODE One or more country codes, delimited by spaces
Use ‘all’ to target all country codes. Use -l to see a list.
-n NUM Exits after NUM IPs have been generated

Unique or repeating:
-u, –unique Return each IP in the countries once only (default)
–repeat IPs can repeat with random order

-s, –sorted Order is sorted, ascending
–random Order is random (default)

-h, –help This message
-l, –list-countries List countries and their country codes
-c DIRECTORY Location of GeoIPCountryWhois.csv database
Default locations: ./, /home/user/.geoipgen/, /usr/local/share/
-V, –version Print version information. This version is 0.4

Example Usage:

How to generate random IPs for the whole world, enumerating each IP once only.
$ geoipgen all

Find out how many IPs are allocated to Israel
$ geoipgen –sorted il | wc -l

How to generate all IPs for New Zealand
$ geoipgen nz

How to generate all IPs for New Zealand and Australia
$ geoipgen nz au

How to generate 10000 IPs in Far East Asia
$ geoipgen -n 10000 cn hk mn tw mo jp kr kp

How to continually generate IPs for the United States, with repeats
$ geoipgen –repeat us

How to reverse resolve a country

This can aid in testing the accuracy of the MaxMind location data by finding IP address blocks potentially attributed to the wrong country. For example, an IP address block could be attributed to New Zealand by Maxmind’s database but when each IP is resolved is found to have many hostnames ending in .sk indicates the ip block belongs to Slovakia and MaxMind has misattributed the location data.

For fast DNS resolution, use an asynchronous resolver like adns.

How to install GNU adns
Download and follow instructions from

$ sudo apt-get install libadns1-bin

Pipe IPs to adnsresfilter and only output resolved IPs

$ ./geoipgen nz | adnsresfilter -w -a | egrep “\[.*\]”

Example Output[][][][][]


Geoipgen uses an algorithm to traverse the IP map returning each IP once only. This algorithm uses some randomness so the pattern should never repeat. This is a much more efficient and faster method than using a bitfield to track whether an IP has been returned.

The first time you generate a set of countries, the countrycode map files are created and saved in ~/.geoipgen/. Subsequent uses are faster because they reload the saved countrycode map.

Related Info

Homepage of the MaxMind GeoLite database
There is an alternative geoIP database here


Geoipgen is authored by Andrew Horton (urbanadventurer) andrew [at]
Thanks to MaxMind for making their GeoLite Country database freely available.

2 thoughts on “GeoIPgen”

  1. Pingback: GeoIPgen: A Tool to Go From Country to IP |

  2. Pingback: GeoIP Country to IP | DC802

Comments are closed.