]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
location-query: Print all information we have
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 13 May 2020 19:50:07 +0000 (19:50 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 13 May 2020 19:50:07 +0000 (19:50 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/location-query.in

index fa3a6cb7a297e02a9c8e57a051dd53dff893e3d0..fb695b0821233138f569a970eb6b4407a0d22063 100644 (file)
@@ -245,37 +245,40 @@ class CLI(object):
        def handle_lookup(self, db, ns):
                ret = 0
 
+               format = "  %-24s: %s"
+
                for address in ns.address:
                        try:
-                               n = db.lookup(address)
+                               network = db.lookup(address)
                        except ValueError:
                                print(_("Invalid IP address: %s") % address, file=sys.stderr)
 
                        args = {
                                "address" : address,
-                               "network" : n,
+                               "network" : network,
                        }
 
                        # Nothing found?
-                       if not n:
+                       if not network:
                                print(_("Nothing found for %(address)s") % args, file=sys.stderr)
                                ret = 1
                                continue
 
-                       # Try to retrieve the AS if we have an AS number
-                       if n.asn:
-                               a = db.get_as(n.asn)
+                       print("%s:" % address)
+                       print(format % (_("Network"), network))
 
-                               # If we have found an AS we will print it in the message
-                               if a:
-                                       args.update({
-                                               "as" : a,
-                                       })
+                       # Print country
+                       if network.country_code:
+                               print(format % (_("Country"), network.country_code))
 
-                                       print(_("%(address)s belongs to %(network)s which is a part of %(as)s") % args)
-                                       continue
+                       # Print AS information
+                       if network.asn:
+                               autonomous_system = db.get_as(network.asn)
 
-                       print(_("%(address)s belongs to %(network)s") % args)
+                               print(format % (
+                                       _("Autonomous System"),
+                                       autonomous_system or "AS%s" % network.asn),
+                               )
 
                return ret