source: genesis/nodes/getrange.py@ 4149

Last change on this file since 4149 was 4149, checked in by lodewijk, 20 years ago

herken andere netmasks dan /30

File size: 920 bytes
Line 
1# zoek de eerste vrije (== niet in een wleiden.conf gedefinieerde) /30
2# lvoge@cs.vu.nl
3import popen2
4import re
5
6ipre = re.compile("^IP=(172\.16\.[0-9]+\.[0-9]+)/([0-9]+) *")
7
8def parseaddr(s):
9 f = s.split('.')
10 return (long(f[0]) << 24L) + \
11 (long(f[1]) << 16L) + \
12 (long(f[2]) << 8L) + \
13 long(f[3])
14
15def showaddr(a):
16 return "%d.%d.%d.%d" % ((a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff)
17
18bezet = {}
19
20(cout, cin) = popen2.popen2("cat */wleiden.conf | grep ^IP | grep 172.16\\\\..*\/30")
21cin.close()
22for l in cout.readlines():
23 l = l[:-1]
24 match = ipre.match(l)
25 if match == None:
26 print "'" + l + "'"
27 addr = parseaddr(match.group(1))
28 mask = int(match.group(2))
29 addr = addr & ~((1 << (32 - mask)) - 1)
30 bezet[addr] = 1
31
32i = 0xffffffffL
33for k in bezet.keys():
34 if k < i:
35 i = k
36
37while bezet.has_key(i):
38 i = i + 4
39
40print "%s/30: %s en %s\n" % (showaddr(i), showaddr(i + 1), showaddr(i + 2))
Note: See TracBrowser for help on using the repository browser.