]> git.ipfire.org Git - ipfire.org.git/blame - src/templates/location/how-to-use/python.html
location: Split the "How To Use?" page into several pages
[ipfire.org.git] / src / templates / location / how-to-use / python.html
CommitLineData
d9e4d7b2
MT
1{% extends "../../base.html" %}
2
3{% block title %}{{ _("How To Use?") }} - {{ _("Python") }}{% end block %}
4
5{% block container %}
6 <section class="hero is-light">
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="/location">
18 {{ _("Location") }}
19 </a>
20 </li>
21 <li>
22 <a href="/location/how-to-use">
23 {{ _("How To Use?") }}
24 </a>
25 </li>
26 <li class="is-active">
27 <a href="#" aria-current="page">{{ _("Python") }}</a>
28 </li>
29 </ul>
30 </nav>
31
32 <h1 class="title">{{ _("Python") }}</h1>
33 </div>
34 </div>
35 </section>
36
37 <section class="section">
38 <div class="container">
39 <div class="columns">
40 <div class="column">
41 <div class="content">
42 <p>
43 <code>libloc</code> comes with native Python bindings which
44 are used by its main command-line tool
45 <a class="text-white" href="https://man-pages.ipfire.org/libloc/location.html">
46 <code>location</code>
47 </a>.
48 They are the most advanced bindings as they support reading
49 from the database as well as writing to it.
50 </p>
51 </div>
52 </div>
53
54 <div class="column is-narrow">
55 <figure class="image is-128x128">
56 <img src="{{ static_url("img/python-logo.svg") }}"
57 alt="{{ _("Python") }}">
58 </figure>
59 </div>
60 </div>
61
62 <div class="block">
63 <h6 class="title is-6">{{ _("Load the database") }}</h6>
64
65 <pre><code>Python 3.7.3 (default, Apr 3 2019, 05:39:12)
66[GCC 8.3.0] on linux
67Type "help", "copyright", "credits" or "license" for more information.
68&gt;&gt;&gt; import location
69&gt;&gt;&gt; d = location.Database("/usr/share/location/database.db")</code></pre>
70 </div>
71
72 <div class="block">
73 <h6 class="title is-6">{{ _("Search for an Autonomous System by Name") }}</h6>
74
75 <pre><code>&gt;&gt;&gt; for i in d.search_as("Lightning Wire Labs"):
76... &nbsp;&nbsp;print(i)
77...
78AS204867 (Lightning Wire Labs GmbH)</code></pre>
79 </div>
80
81 <div class="block">
82 <h6 class="title is-6">{{ _("Lookup an IP Address") }}</h6>
83
84 <pre><code>&gt;&gt;&gt; n = d.lookup("81.3.27.38")
85&gt;&gt;&gt; n
86&lt;location.Network 81.3.27.0/24&gt;
87&gt;&gt;&gt; n.asn
8824679
89&gt;&gt;&gt; n.country_code
90'DE'</code></pre>
91 </div>
92 </div>
93 </section>
94{% end block %}