source: genesis/nodes/getrange.py@ 7923

Last change on this file since 7923 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
RevLine 
[7089]1#!/usr/bin/env python
[4150]2# zoek de eerste vrije (== niet in een wleiden.conf gedefinieerde) interlink
3# range
[5283]4# lodewijk@wirelessleiden.nl
[3130]5import popen2
6import re
[4150]7import sys
[3130]8
[4150]9size = 30
[7325]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])
[4150]16numaddrs = 1 << (32 - size)
17
[4149]18ipre = re.compile("^IP=(172\.16\.[0-9]+\.[0-9]+)/([0-9]+) *")
[3130]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
[7460]32(cout, cin) = popen2.popen2("cat */wleiden.conf | grep ^IP | grep 172.16\...*\/[24\|26\|28\|29\|30]")
[3130]33cin.close()
34for l in cout.readlines():
35 l = l[:-1]
36 match = ipre.match(l)
37 if match == None:
[5809]38 #print "'" + l + "'"
39 continue
40 if len(match.groups()) == 0:
41 continue
[3130]42 addr = parseaddr(match.group(1))
[4149]43 mask = int(match.group(2))
44 addr = addr & ~((1 << (32 - mask)) - 1)
[3130]45 bezet[addr] = 1
46
47i = 0xffffffffL
48for k in bezet.keys():
49 if k < i:
50 i = k
51
[6024]52
53i = 0xac100300
[7325]54if not interlink:
[5519]55 i = 0xac110000
[3130]56while bezet.has_key(i):
[4150]57 i = i + numaddrs
[3130]58
[4150]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.