{% extends "../base.html" %} {% block title %}{{ _("How To Use") }}{% end block %} {% block container %}

{{ _("How To Use") }}

libloc is versatile, fast and easy to use in any application.

{{ _(

{{ _("Command Line") }}

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") }}
{{ _("Search for an Autonomous System by Name") }}
$ location search-as "Lightning Wire Labs"
AS204867 (Lightning Wire Labs GmbH)
{{ _("Lookup an IP Address") }}
$ location -d test.db lookup 81.3.27.38
81.3.27.38 belongs to 81.3.27.0/24 which is a part of AS24679 (Hostway Deutschland GmbH)
{{ _(

{{ _("Python") }}

libloc comes with native Python bindings which are used by its main command-line tool location . They are the most advanced bindings as they support reading from the database as well as writing to it.

{{ _("Load the database") }}
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")
{{ _("Search for an Autonomous System by Name") }}
>>> for i in d.search_as("Lightning Wire Labs"):
...   print(i)
...
AS204867 (Lightning Wire Labs GmbH)
{{ _("Lookup an IP Address") }}
>>> n = d.lookup("81.3.27.38")
>>> n
<location.Network 81.3.27.0/24>
>>> n.asn
24679
>>> n.country_code
'DE'
{% end block %}