]> git.ipfire.org Git - ipfire.org.git/blob - src/templates/location/how-to-use.html
location: Fix spacing in Python example code
[ipfire.org.git] / src / templates / location / how-to-use.html
1 {% extends "../base.html" %}
2
3 {% block title %}{{ _("How To Use") }}{% end block %}
4
5 {% block container %}
6 <section>
7 <div class="container">
8 <div class="row">
9 <div class="col col-lg-6">
10 <h1 class="display-2">{{ _("How To Use") }}</h1>
11
12 <p>
13 <code>libloc</code> is versatile, fast and easy to use
14 in any application.
15 </p>
16 </div>
17 </div>
18 </div>
19 </section>
20
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") }}"
26 alt="{{ _("CLI") }}">
27 </div>
28
29 <div class="col-12 col-md-8">
30 <h1>{{ _("Command Line") }}</h1>
31
32 <p>
33 <code>libloc</code> comes with a command line tool which
34 makes it easy to test the library or integrate it into
35 your shell scripts.
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
39 other software.
40 </p>
41
42 <p>
43 Although this is not the fastest way to lookup a large number
44 of IP addresses, <code>location(8)</code> is versatile
45 and very easy to use.
46 </p>
47
48 <a class="btn btn-secondary" href="https://man-pages.ipfire.org/libloc/location.html">
49 {{ _("Man Page") }}
50 </a>
51 </div>
52 </div>
53
54 <div class="row">
55 <div class="col-12">
56 <h6>{{ _("Search for an Autonomous System by Name") }}</h6>
57
58 <pre class="mb-4"><code>$ location search-as "Lightning Wire Labs"
59 AS204867 (Lightning Wire Labs GmbH)</code></pre>
60
61 <h6>{{ _("Lookup an IP Address") }}</h6>
62
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>
65 </div>
66 </div>
67 </div>
68 </section>
69
70 <section>
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") }}">
76 </div>
77
78 <div class="col-12 col-md-6">
79 <h1>{{ _("Python") }}</h1>
80
81 <p>
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">
85 <code>location</code>
86 </a>.
87 They are the most advanced bindings as they support reading
88 from the database as well as writing to it.
89 </p>
90 </div>
91 </div>
92
93 <div class="row">
94 <div class="col-12">
95 <h6>{{ _("Load the database") }}</h6>
96
97 <pre class="pre-light mb-4"><code>Python 3.7.3 (default, Apr 3 2019, 05:39:12)
98 [GCC 8.3.0] on linux
99 Type "help", "copyright", "credits" or "license" for more information.
100 &gt;&gt;&gt; import location
101 &gt;&gt;&gt; d = location.Database("/usr/share/location/database.db")</code></pre>
102
103 <h6>{{ _("Search for an Autonomous System by Name") }}</h6>
104
105 <pre class="pre-light mb-4"><code>&gt;&gt;&gt; for i in d.search_as("Lightning Wire Labs"):
106 ... &nbsp;&nbsp;print(i)
107 ...
108 AS204867 (Lightning Wire Labs GmbH)</code></pre>
109
110 <h6>{{ _("Lookup an IP Address") }}</h6>
111
112 <pre class="pre-light"><code>&gt;&gt;&gt; n = d.lookup("81.3.27.38")
113 &gt;&gt;&gt; n
114 &lt;location.Network 81.3.27.0/24&gt;
115 &gt;&gt;&gt; n.asn
116 24679
117 &gt;&gt;&gt; n.country_code
118 'DE'</code></pre>
119 </div>
120 </div>
121 </div>
122 </section>
123 {% end block %}