libloc is versatile, fast and easy to use
in any application.
libloc comes with a command line tool which
makes it easy to test the library or integrate it into
your shell scripts.
location(8) knows a couple of commands
to retrieve country or Autonomous System of an IP address
and can generate lists of networks to be imported into
Although this is not the fastest way to lookup a large number
of IP addresses,
location(8) is versatile
and very easy to use.
$ location search-as "Lightning Wire Labs" AS204867 (Lightning Wire Labs GmbH)
$ location lookup 126.96.36.199 188.8.131.52 belongs to 184.108.40.206/24 which is a part of AS24679 (Hostway Deutschland GmbH)
libloc comes with native Python bindings which
are used by its main command-line tool
They are the most advanced bindings as they support reading
from the database as well as writing to it.
Python 3.7.3 (default, Apr 3 2019, 05:39:12) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import location >>> d = location.Database("/usr/share/location/database.db")
>>> for i in d.search_as("Lightning Wire Labs"): ... print(i) ... AS204867 (Lightning Wire Labs GmbH)
>>> n = d.lookup("220.127.116.11") >>> n <location.Network 18.104.22.168/24> >>> n.asn 24679 >>> n.country_code 'DE'