aboutsummaryrefslogtreecommitdiff
path: root/utils/ipaddr2list.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/ipaddr2list.py')
-rwxr-xr-xutils/ipaddr2list.py43
1 files changed, 21 insertions, 22 deletions
diff --git a/utils/ipaddr2list.py b/utils/ipaddr2list.py
index 2aa244b35..9dcee0820 100755
--- a/utils/ipaddr2list.py
+++ b/utils/ipaddr2list.py
@@ -1,23 +1,22 @@
#!/usr/bin/env python3
import sys
-import socket, struct
+import socket
-# This scripts is mainly used to create "ip -> protocols" lists.
-# However it is also used to create "ip -> risk" lists
+# These scripts are mainly used to create "ip -> protocols" lists.
+# However, it is also used to create "ip -> risk" lists
proto = "NDPI_PROTOCOL_XYX"
append_name = ""
-if len (sys.argv) < 2 :
+if len(sys.argv) < 2:
print("Usage: ipaddr2list.py <file> <protocol> [file6] [<append_name>]")
- sys.exit (1)
+ sys.exit(1)
-if len (sys.argv) >= 3:
+if len(sys.argv) >= 3:
proto = sys.argv[2]
-if len (sys.argv) >= 5:
+if len(sys.argv) >= 5:
append_name = sys.argv[4]
-
print("""/*
*
* This file is generated automatically and part of nDPI
@@ -41,53 +40,53 @@ print("""/*
""")
-print("static ndpi_network "+proto.lower()+append_name+"_protocol_list[] = {")
+print("static ndpi_network " + proto.lower() + append_name + "_protocol_list[] = {")
lines = 0
with open(sys.argv[1]) as fp:
for cnt, line in enumerate(fp):
line = line.rstrip()
- if(line != ""):
+ if line != "":
lines += 1
x = line.split("/")
- if(len(x) == 2):
+ if len(x) == 2:
ipaddr = x[0]
- cidr = x[1]
+ cidr = x[1]
else:
ipaddr = line
cidr = "32"
- if(ipaddr != ""):
- print(" { 0x"+socket.inet_aton(ipaddr).hex().upper()+" /* "+ipaddr+"/"+cidr+" */, "+cidr+", "+proto+" },")
+ if ipaddr != "":
+ print(" { 0x" + socket.inet_aton(ipaddr).hex().upper() + " /* " + ipaddr + "/" + cidr + " */, " + cidr + ", " + proto + " },")
print(" /* End */")
print(" { 0x0, 0, 0 }")
print("};")
-print("");
-print("static ndpi_network6 "+proto.lower()+append_name+"_protocol_list_6[] = {")
+print("")
+print("static ndpi_network6 " + proto.lower() + append_name + "_protocol_list_6[] = {")
-if(len (sys.argv) >= 4):
+if len(sys.argv) >= 4:
with open(sys.argv[3]) as fp:
for cnt, line in enumerate(fp):
line = line.rstrip()
- if(line != ""):
+ if line != "":
lines += 1
x = line.split("/")
- if(len(x) == 2):
+ if len(x) == 2:
ipaddr = x[0]
- cidr = x[1]
+ cidr = x[1]
else:
ipaddr = line
cidr = "128"
- if(ipaddr != ""):
- print(" { \""+ipaddr+"\", "+cidr+", "+proto+" },")
+ if ipaddr != "":
+ print(" { \"" + ipaddr + "\", " + cidr + ", " + proto + " },")
print(" /* End */")
print(" { NULL, 0, 0 }")