-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateiplist.py
More file actions
executable file
·33 lines (27 loc) · 849 Bytes
/
Copy pathcreateiplist.py
File metadata and controls
executable file
·33 lines (27 loc) · 849 Bytes
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
27
28
29
30
31
32
33
#!/usr/bin/python
# Reads ip prefixes from stdin and creates a list of ips and outputs them to
# the file specified in the command
import sys, socket, struct
IP_BITS = 32
IP_MAX = 0xffffffff
def prefixToInt(prefix):
octets = prefix.split('.')
value = 0;
value = value | (int(octets[0]) << 24)
value = value | (int(octets[1]) << 16)
value = value | (int(octets[2]) << 8)
return value
def processPrefix(prefix):
split = prefix.split('/')
network = split[0]
mask = int(split[1])
networkVal = prefixToInt(network)
minVal = 0
maxVal = (IP_MAX >> mask)
for i in range(minVal, maxVal + 1):
currentIp = networkVal + i
print socket.inet_ntoa(struct.pack('>L', currentIp))
for line in sys.stdin:
prefixes = line.split(' ')
for prefix in prefixes:
processPrefix(prefix)