1 {% extends
"../../base.html" %}
3 {% block title %}{{ _(
"How To Use?") }}{% end block %}
6 <section class=
"hero is-primary">
7 <div class=
"hero-body">
8 <div class=
"container">
9 <nav class=
"breadcrumb" aria-label=
"breadcrumbs">
21 <li class=
"is-active">
22 <a href=
"#" aria-current=
"page">{{ _(
"How to use?") }}
</a>
27 <h1 class=
"title">{{ _(
"IPFire Location") }}
</h1>
29 <code>libloc
</code> is versatile, fast and easy to use
36 <section class=
"section">
37 <div class=
"container">
40 <h2 class=
"title is-2">{{ _(
"Command Line") }}
</h2>
44 <code>libloc
</code> comes with a command line tool which
45 makes it easy to test the library or integrate it into
47 <code>location(
8)
</code> knows a couple of commands
48 to retrieve country or Autonomous System of an IP address
49 and can generate lists of networks to be imported into
54 Although this is not the fastest way to lookup a large number
55 of IP addresses,
<code>location(
8)
</code> is versatile
59 <a class=
"button is-light" href=
"https://man-pages.ipfire.org/libloc/location.html">
65 <div class=
"column is-narrow">
66 <figure class=
"image is-256x256">
67 <img src=
"{{ static_url("img/bash-logo.svg
") }}" alt=
"{{ _("CLI
") }}">
73 <h6 class=
"title is-6">{{ _(
"Search for an Autonomous System by Name") }}
</h6>
75 <pre><code>$ location search-as
"Lightning Wire Labs"
76 AS204867 (Lightning Wire Labs GmbH)
</code></pre>
80 <h6 class=
"title is-6">{{ _(
"Lookup an IP Address") }}
</h6>
82 <pre><code>$ location lookup
81.3.27.38
83 81.3.27.38 belongs to
81.3.27.0/
24 which is a part of AS24679 (Hostway Deutschland GmbH)
</code></pre>
88 <section class=
"section">
89 <div class=
"container">
91 <div class=
"column is-narrow">
92 <figure class=
"image is-256x256">
93 <img src=
"{{ static_url("img/python-logo.svg
") }}"
94 alt=
"{{ _("Python
") }}">
99 <h2 class=
"title is-2">{{ _(
"Python") }}
</h2>
101 <div class=
"content">
103 <code>libloc
</code> comes with native Python bindings which
104 are used by its main command-line tool
105 <a class=
"text-white" href=
"https://man-pages.ipfire.org/libloc/location.html">
106 <code>location
</code>
108 They are the most advanced bindings as they support reading
109 from the database as well as writing to it.
116 <h6 class=
"title is-6">{{ _(
"Load the database") }}
</h6>
118 <pre><code>Python
3.7.3 (default, Apr
3 2019,
05:
39:
12)
120 Type
"help",
"copyright",
"credits" or
"license" for more information.
121 >>> import location
122 >>> d = location.Database(
"/usr/share/location/database.db")
</code></pre>
126 <h6 class=
"title is-6">{{ _(
"Search for an Autonomous System by Name") }}
</h6>
128 <pre><code>>>> for i in d.search_as(
"Lightning Wire Labs"):
129 ...
print(i)
131 AS204867 (Lightning Wire Labs GmbH)
</code></pre>
135 <h6 class=
"title is-6">{{ _(
"Lookup an IP Address") }}
</h6>
137 <pre><code>>>> n = d.lookup(
"81.3.27.38")
139 <location.Network
81.3.27.0/
24>
142 >>> n.country_code