aboutsummaryrefslogtreecommitdiff
path: root/utils/toripaddr2list.py
blob: 0257e4098387f378fa6cec0fe47eb39f7ce95dab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python3

import sys
import socket, struct

if len (sys.argv) != 2 :
    print("Usage: toripaddr2list.py <file>")
    sys.exit (1)
            
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+", NDPI_PROTOCOL_XYX },")