1 {% extends
"../base.html" %}
3 {% block title %}{{ _(
"How To Use") }}{% end block %}
7 <div class=
"container">
9 <div class=
"col col-lg-6">
10 <h1 class=
"display-2">{{ _(
"How To Use") }}
</h1>
13 <code>libloc
</code> is versatile, fast and easy to use
21 <section class=
"inverse">
22 <div class=
"container">
23 <div class=
"row justify-content-between flex-md-row-reverse">
24 <div class=
"col-12 col-md-4 text-center text-md-right">
25 <img class=
"img-fluid w-100 my-5" src=
"{{ static_url("img/bash-logo.svg
") }}"
29 <div class=
"col-12 col-md-8">
30 <h1>{{ _(
"Command Line") }}
</h1>
33 <code>libloc
</code> comes with a command line tool which
34 makes it easy to test the library or integrate it into
36 <code>location(
8)
</code> knows a couple of commands
37 to retrieve country or Autonomous System of an IP address
38 and can generate lists of networks to be imported into
43 Although this is not the fastest way to lookup a large number
44 of IP addresses,
<code>location(
8)
</code> is versatile
48 <a class=
"btn btn-secondary" href=
"https://man-pages.ipfire.org/libloc/location.html">
56 <h6>{{ _(
"Search for an Autonomous System by Name") }}
</h6>
58 <pre class=
"mb-4"><code>$ location search-as
"Lightning Wire Labs"
59 AS204867 (Lightning Wire Labs GmbH)
</code></pre>
61 <h6>{{ _(
"Lookup an IP Address") }}
</h6>
63 <pre class=
"mb-4"><code>$ location lookup
81.3.27.38
64 81.3.27.38 belongs to
81.3.27.0/
24 which is a part of AS24679 (Hostway Deutschland GmbH)
</code></pre>
71 <div class=
"container">
72 <div class=
"row justify-content-between flex-md-row-reverse">
73 <div class=
"col-12 col-md-4 text-center text-md-right">
74 <img class=
"img-fluid w-100 my-5" src=
"{{ static_url("img/python-logo.svg
") }}"
75 alt=
"{{ _("Python
") }}">
78 <div class=
"col-12 col-md-6">
79 <h1>{{ _(
"Python") }}
</h1>
82 <code>libloc
</code> comes with native Python bindings which
83 are used by its main command-line tool
84 <a class=
"text-white" href=
"https://man-pages.ipfire.org/libloc/location.html">
87 They are the most advanced bindings as they support reading
88 from the database as well as writing to it.
95 <h6>{{ _(
"Load the database") }}
</h6>
97 <pre class=
"pre-light mb-4"><code>Python
3.7.3 (default, Apr
3 2019,
05:
39:
12)
99 Type
"help",
"copyright",
"credits" or
"license" for more information.
100 >>> import location
101 >>> d = location.Database(
"/usr/share/location/database.db")
</code></pre>
103 <h6>{{ _(
"Search for an Autonomous System by Name") }}
</h6>
105 <pre class=
"pre-light mb-4"><code>>>> for i in d.search_as(
"Lightning Wire Labs"):
106 ...
print(i)
108 AS204867 (Lightning Wire Labs GmbH)
</code></pre>
110 <h6>{{ _(
"Lookup an IP Address") }}
</h6>
112 <pre class=
"pre-light"><code>>>> n = d.lookup(
"81.3.27.38")
114 <location.Network
81.3.27.0/
24>
117 >>> n.country_code