]> git.ipfire.org Git - ipfire.org.git/blob - src/templates/location/how-to-use.html
ddc75beeb9791338ccc20dbfc64a47435694c340
[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 class="hero is-primary">
7 <div class="hero-body">
8 <div class="container">
9 <nav class="breadcrumb" aria-label="breadcrumbs">
10 <ul>
11 <li>
12 <a href="/">
13 {{ _("Home") }}
14 </a>
15 </li>
16 <li>
17 <a href="#">
18 {{ _("Projects") }}
19 </a>
20 </li>
21 <li>
22 <a href="/projects/location">
23 {{ _("Location") }}
24 </a>
25 </li>
26 <li class="is-active">
27 <a href="#" aria-current="page">{{ _("How to use?") }}</a>
28 </li>
29 </ul>
30 </nav>
31
32 <h1 class="title">{{ _("IPFire Location") }}</h1>
33 <h6 class="subtitle">
34 <code>libloc</code> is versatile, fast and easy to use
35 in any application.
36 </h6>
37 </div>
38 </div>
39 </section>
40
41 <section class="section">
42 <div class="container">
43 <div class="columns">
44 <div class="column">
45 <h2 class="title is-2">{{ _("Command Line") }}</h2>
46
47 <div class="content">
48 <p>
49 <code>libloc</code> comes with a command line tool which
50 makes it easy to test the library or integrate it into
51 your shell scripts.
52 <code>location(8)</code> knows a couple of commands
53 to retrieve country or Autonomous System of an IP address
54 and can generate lists of networks to be imported into
55 other software.
56 </p>
57
58 <p>
59 Although this is not the fastest way to lookup a large number
60 of IP addresses, <code>location(8)</code> is versatile
61 and very easy to use.
62 </p>
63
64 <a class="button is-light" href="https://man-pages.ipfire.org/libloc/location.html">
65 {{ _("Man Page") }}
66 </a>
67 </div>
68 </div>
69
70 <div class="column is-narrow">
71 <figure class="image is-256x256">
72 <img src="{{ static_url("img/bash-logo.svg") }}" alt="{{ _("CLI") }}">
73 </figure>
74 </div>
75 </div>
76
77 <div class="block">
78 <h6 class="title is-6">{{ _("Search for an Autonomous System by Name") }}</h6>
79
80 <pre><code>$ location search-as "Lightning Wire Labs"
81 AS204867 (Lightning Wire Labs GmbH)</code></pre>
82 </div>
83
84 <div class="block">
85 <h6 class="title is-6">{{ _("Lookup an IP Address") }}</h6>
86
87 <pre><code>$ location lookup 81.3.27.38
88 81.3.27.38 belongs to 81.3.27.0/24 which is a part of AS24679 (Hostway Deutschland GmbH)</code></pre>
89 </div>
90 </div>
91 </section>
92
93 <section class="section">
94 <div class="container">
95 <div class="columns">
96 <div class="column is-narrow">
97 <figure class="image is-256x256">
98 <img src="{{ static_url("img/python-logo.svg") }}"
99 alt="{{ _("Python") }}">
100 </figure>
101 </div>
102
103 <div class="column">
104 <h2 class="title is-2">{{ _("Python") }}</h2>
105
106 <div class="content">
107 <p>
108 <code>libloc</code> comes with native Python bindings which
109 are used by its main command-line tool
110 <a class="text-white" href="https://man-pages.ipfire.org/libloc/location.html">
111 <code>location</code>
112 </a>.
113 They are the most advanced bindings as they support reading
114 from the database as well as writing to it.
115 </p>
116 </div>
117 </div>
118 </div>
119
120 <div class="block">
121 <h6 class="title is-6">{{ _("Load the database") }}</h6>
122
123 <pre><code>Python 3.7.3 (default, Apr 3 2019, 05:39:12)
124 [GCC 8.3.0] on linux
125 Type "help", "copyright", "credits" or "license" for more information.
126 &gt;&gt;&gt; import location
127 &gt;&gt;&gt; d = location.Database("/usr/share/location/database.db")</code></pre>
128 </div>
129
130 <div class="block">
131 <h6 class="title is-6">{{ _("Search for an Autonomous System by Name") }}</h6>
132
133 <pre><code>&gt;&gt;&gt; for i in d.search_as("Lightning Wire Labs"):
134 ... &nbsp;&nbsp;print(i)
135 ...
136 AS204867 (Lightning Wire Labs GmbH)</code></pre>
137 </div>
138
139 <div class="block">
140 <h6 class="title is-6">{{ _("Lookup an IP Address") }}</h6>
141
142 <pre><code>&gt;&gt;&gt; n = d.lookup("81.3.27.38")
143 &gt;&gt;&gt; n
144 &lt;location.Network 81.3.27.0/24&gt;
145 &gt;&gt;&gt; n.asn
146 24679
147 &gt;&gt;&gt; n.country_code
148 'DE'</code></pre>
149 </div>
150 </div>
151 </section>
152 {% end block %}