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 other software.

Although this is not the fastest way to lookup a large number of IP addresses, location(8) is versatile and very easy to use.

Man Page
CLI
Search for an Autonomous System by Name
$ location search-as "Lightning Wire Labs"
AS204867 - Lightning Wire Labs GmbH
Lookup an IP Address
$ location lookup 81.3.27.38
81.3.27.38:
  Network                 : 81.3.0.0/18
  Country                 : Germany
  Autonomous System       : AS24679 - kyberio GmbH

Keep The Database Up To Date

location update downloads a new database if there is one, checks its signature and then replaces the old database. Whether there is a new database is announced in the DNS, so nothing is downloaded when there is nothing new.

$ location update

When running from a cron job, --cron makes sure that the database is only updated once a day, week or month:

$ location update --cron daily

To check the signature of the database that is already installed, run:

$ location verify

Export For A Firewall

location export writes all networks of countries and Autonomous Systems in a format that can be loaded into a packet filter. The networks are broken down so that none of them overlap. The formats are list, nftables, ipset and xt_geoip.

$ location export --format=nftables DE
define DEv6 = {
	...
}
define DEv4 = {
	...
}

With --directory, every country and Autonomous System is written into its own file for IPv4 and IPv6:

$ location export --format=nftables --directory=/var/lib/nftables DE AS204867
$ ls /var/lib/nftables
AS204867v4.set  AS204867v6.set  DEv4.set  DEv6.set

To list all bogons, which is address space that should not be seen on the Internet at all, run:

$ location list-bogons