]> git.ipfire.org Git - location/libloc.git/blobdiff - src/python/location.in
Implement an additional flag for hostile networks safe to drop
[location/libloc.git] / src / python / location.in
index e02b4e891d3b0844758267ce7d686369f696d8a4..0c89d75263370952259255a5470aa4884685b1b1 100644 (file)
@@ -3,7 +3,7 @@
 #                                                                             #
 # libloc - A library to determine the location of someone on the Internet     #
 #                                                                             #
-# Copyright (C) 2017 IPFire Development Team <info@ipfire.org>                #
+# Copyright (C) 2017-2021 IPFire Development Team <info@ipfire.org>           #
 #                                                                             #
 # This library is free software; you can redistribute it and/or               #
 # modify it under the terms of the GNU Lesser General Public                  #
@@ -146,6 +146,9 @@ class CLI(object):
                list_networks_by_flags.add_argument("--anycast",
                        action="store_true", help=_("Anycasts"),
                )
+               list_networks_by_flags.add_argument("--drop",
+                       action="store_true", help=_("Hostile Networks safe to drop"),
+               )
                list_networks_by_flags.add_argument("--family", choices=("ipv6", "ipv4"))
                list_networks_by_flags.add_argument("--format",
                        choices=location.export.formats.keys(), default="list")
@@ -305,6 +308,12 @@ class CLI(object):
                                        _("Anycast"), _("yes"),
                                ))
 
+                       # Hostile Network
+                       if network.has_flag(location.NETWORK_FLAG_DROP):
+                               print(format % (
+                                       _("Hostile Network safe to drop"), _("yes"),
+                               ))
+
                return ret
 
        def handle_dump(self, db, ns):
@@ -346,6 +355,7 @@ class CLI(object):
                        location.NETWORK_FLAG_ANONYMOUS_PROXY    : "is-anonymous-proxy:",
                        location.NETWORK_FLAG_SATELLITE_PROVIDER : "is-satellite-provider:",
                        location.NETWORK_FLAG_ANYCAST            : "is-anycast:",
+                       location.NETWORK_FLAG_DROP               : "drop:",
                }
 
                # Iterate over all networks
@@ -523,6 +533,9 @@ class CLI(object):
                if ns.anycast:
                        flags |= location.NETWORK_FLAG_ANYCAST
 
+               if ns.drop:
+                       flags |= location.NETWORK_FLAG_DROP
+
                if not flags:
                        raise ValueError(_("You must at least pass one flag"))
 
@@ -551,7 +564,7 @@ class CLI(object):
                                asns.append(object)
 
                        elif location.country_code_is_valid(object) \
-                                       or object in ("A1", "A2", "A3"):
+                                       or object in ("A1", "A2", "A3", "XD"):
                                countries.append(object)
 
                        else:
@@ -560,7 +573,7 @@ class CLI(object):
 
                # Default to exporting all countries
                if not countries and not asns:
-                       countries = ["A1", "A2", "A3"] + [country.code for country in db.countries]
+                       countries = ["A1", "A2", "A3", "XD"] + [country.code for country in db.countries]
 
                # Select the output format
                writer = self.__get_output_formatter(ns)