directly loaded into other software. The following options are available:
+
* 'list' (default): Just lists all networks, one per line
+ * 'nftables': For nftables
* 'xt_geoip': Returns a list of networks to be loaded into the xt_geoip
kernel module
# Output formatters
class OutputFormatter(object):
+ def __init__(self, ns):
+ self.ns = ns
+
def __enter__(self):
# Open the output
self.open()
if tb is None:
self.close()
+ @property
+ def name(self):
+ if "country_code" in self.ns:
+ return "networks_country_%s" % self.ns.country_code[0]
+
+ elif "asn" in self.ns:
+ return "networks_AS%s" % self.ns.asn[0]
+
def open(self):
pass
print(network)
+class NftablesOutputFormatter(OutputFormatter):
+ """
+ For nftables
+ """
+ def open(self):
+ print("define %s = {" % self.name)
+
+ def close(self):
+ print("}")
+
+ def network(self, network):
+ print(" %s," % network)
+
+
class XTGeoIPOutputFormatter(OutputFormatter):
"""
Formats the output in that way, that it can be loaded by
class CLI(object):
output_formats = {
"list" : OutputFormatter,
+ "nftables" : NftablesOutputFormatter,
"xt_geoip" : XTGeoIPOutputFormatter,
}
except KeyError:
cls = OutputFormatter
- return cls()
+ return cls(ns)
def handle_list_networks_by_as(self, db, ns):
with self.__get_output_formatter(ns) as f: