back to index



ip2loc: Determining geographical position from an IP address. Designed for easy use in scripts.
ipdiffmask: Converting between and style notations.

Mechanism of work

Program uses a file with a table of IP ranges vs the countries.
Inspired by mod_geo, from where I "borrowed" the location and country code files.


Usage: ip2loc [-i] [-c] IP ...
Shows countries or country codes for IP addresses.

   -i          show IP
   -c          show country as code instead as name
   -C          do not show country
   -r          show IP range
   -m          show all matching ranges
   -n          do not show trailing \n
   -L <code>   show country code <code>
   -R <code>   show IP ranges for country <code>
   -G <file>   use <file> as geolocation file instead of /usr/share/ip-geo.ids

When IP is '-', the addresses are read from stdin.

When the IPs are read from stdin, the rest of the line after the IP address is ignored, making this tool suitable for processing scripts.


ip2loc   Determine country of
ip2loc -r -C   Show only IP range belongs to
ip2loc -c   Determine country of and, show as code
ip2loc -m -r   Show ranges for all matching entries, not only the closest match
ip2loc -L CZ   Show the country with code CZ
ip2loc -R CZ   List all the known IP ranges of CZ

You came from , which is Usage: /bin/shad/ip2loc Queries and parses the output. IP address locator is using Maxmind GeoLite's database for finding the location of the IP address. and belongs to segment IP address: .


Part of the project is a very simple utility for transcoding network IP ranges between the IP/mask and IP..IP notations.


ipdiffmask   Shows
ipdiffmask   Shows


The file is out of date. Accuracy is not always guaranteed.


Get the IP ranges list from and convert them to the format suitable for ip2loc.

Add databases from


ip2loc.c - the program source itself
ip-geo.ids - the IP-to-country map file. Goes to /usr/share/ip-geo.ids
country-codes.txt - the country-code-to-name file. Goes to /usr/share/country-codes.txt

ipdiffmask.c - source of ipdiffmask utility

If you have any comments or questions about the topic, please let me know here:
Your name:
Your email:
Leave this empty!
Only spambots enter stuff here.