source: genesis/nodes/getrange.py@ 7677

Last change on this file since 7677 was 7460, checked in by huub, 15 years ago

release parameter updated for 7.2-RELEASE info

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.4 KB
Line 
1#!/usr/bin/env python
2# zoek de eerste vrije (== niet in een wleiden.conf gedefinieerde) interlink
3# range
4# lodewijk@wirelessleiden.nl
5import popen2
6import re
7import sys
8
9size = 30
10if len(sys.argv) < 2:
11 print "Gebruik: python getrange.py <interlink|subnet> <size>"
12 print "dus voor een /28 interlink is het 'python getrange.py interlink 28'"
13 print "en voor een /25 subnet is het 'python getrange.py subnet 25'"
14interlink = sys.argv[1] == 'interlink'
15size = int(sys.argv[2])
16numaddrs = 1 << (32 - size)
17
18ipre = re.compile("^IP=(172\.16\.[0-9]+\.[0-9]+)/([0-9]+) *")
19
20def parseaddr(s):
21 f = s.split('.')
22 return (long(f[0]) << 24L) + \
23 (long(f[1]) << 16L) + \
24 (long(f[2]) << 8L) + \
25 long(f[3])
26
27def showaddr(a):
28 return "%d.%d.%d.%d" % ((a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff)
29
30bezet = {}
31
32(cout, cin) = popen2.popen2("cat */wleiden.conf | grep ^IP | grep 172.16\...*\/[24\|26\|28\|29\|30]")
33cin.close()
34for l in cout.readlines():
35 l = l[:-1]
36 match = ipre.match(l)
37 if match == None:
38 #print "'" + l + "'"
39 continue
40 if len(match.groups()) == 0:
41 continue
42 addr = parseaddr(match.group(1))
43 mask = int(match.group(2))
44 addr = addr & ~((1 << (32 - mask)) - 1)
45 bezet[addr] = 1
46
47i = 0xffffffffL
48for k in bezet.keys():
49 if k < i:
50 i = k
51
52
53i = 0xac100300
54if not interlink:
55 i = 0xac110000
56while bezet.has_key(i):
57 i = i + numaddrs
58
59print "%s/%d:" % (showaddr(i), size),
60print " en ".join([showaddr(i) for i in range(i + 1, i + numaddrs - 1)])
Note: See TracBrowser for help on using the repository browser.