From fadc1af0ee16a1dc1b08ad5d4655342a6e6364ce Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 1 Feb 2018 14:13:48 +0000 Subject: [PATCH] location-query: Implement getting information about an AS Signed-off-by: Michael Tremer --- src/python/location-query.in | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/python/location-query.in b/src/python/location-query.in index b5c1008..933024e 100644 --- a/src/python/location-query.in +++ b/src/python/location-query.in @@ -58,6 +58,13 @@ class CLI(object): lookup.add_argument("address", nargs="+") lookup.set_defaults(func=self.handle_lookup) + # Get AS + get_as = subparsers.add_parser("get-as", + help=_("Get information about one or multiple Autonomous Systems"), + ) + get_as.add_argument("asn", nargs="+") + get_as.set_defaults(func=self.handle_get_as) + return parser.parse_args() def run(self): @@ -114,6 +121,32 @@ class CLI(object): return ret + def handle_get_as(self, ns): + """ + Gets information about Autonomous Systems + """ + ret = 0 + + for asn in ns.asn: + try: + asn = int(asn) + except ValueError: + sys.stderr.write("Invalid ASN: %s" %asn) + ret = 1 + continue + + # Fetch AS from database + a = self.db.get_as(asn) + + # Nothing found + if not a: + print(_("Could not find AS%s") % asn) + ret = 1 + continue + + print(_("AS%(asn)s belongs to %(name)s") % { "asn" : a.number, "name" : a.name }) + + return ret def main(): # Run the command line interface -- 2.39.2