source: genesis/nodes/getrange.py@ 4309

Last change on this file since 4309 was 4162, checked in by rick, 20 years ago

Interlinks kunnen ook in de /29 of /28 range liggen

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