aboutsummaryrefslogtreecommitdiff
path: root/utils/ipaddr2list.py
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2021-12-19 18:59:45 +0100
committerLuca Deri <deri@ntop.org>2021-12-19 18:59:45 +0100
commit7aad97fffbdd37f206a4164d6b61945b03dfbbc2 (patch)
tree18acecc6b03b727ace21ee8183a45ccd409141f9 /utils/ipaddr2list.py
parent7153b8933ca6a3df3f6de7d47cbb25e66a8970d4 (diff)
Added Microsoft Azure support
Diffstat (limited to 'utils/ipaddr2list.py')
-rwxr-xr-xutils/ipaddr2list.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/utils/ipaddr2list.py b/utils/ipaddr2list.py
new file mode 100755
index 000000000..9fb103a99
--- /dev/null
+++ b/utils/ipaddr2list.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+
+import sys
+import socket, struct
+
+proto = "NDPI_PROTOCOL_XYX"
+if len (sys.argv) < 2 :
+ print("Usage: ipaddr2list.py <file> <protocol>")
+ sys.exit (1)
+
+if len (sys.argv) == 3:
+ proto = sys.argv[2]
+
+
+
+print("""/*
+ *
+ * This file is generated automatically and part of nDPI
+ *
+ * nDPI is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * nDPI is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/* ****************************************************** */
+
+""")
+
+print("static ndpi_network "+proto.lower()+"_protocol_list[] = {")
+
+with open(sys.argv[1]) as fp:
+ for cnt, line in enumerate(fp):
+ line = line.rstrip()
+
+ if(line != ""):
+ x = line.split("/")
+
+ if(len(x) == 2):
+ ipaddr = x[0]
+ cidr = x[1]
+ else:
+ ipaddr = line
+ cidr = "32"
+
+ if(ipaddr != ""):
+ print(" { 0x"+socket.inet_aton(ipaddr).hex().upper()+" /* "+ipaddr+"/"+cidr+" */, "+cidr+", "+proto+" },")
+
+
+print("};")