source: genesis/nodes/getrange.py@ 7091

Last change on this file since 7091 was 7089, checked in by rick, 15 years ago

Beeing lacy, saves me from typing python getrange.py, but use ./getrange.py instead

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.2 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) > 1:
11 size = int(sys.argv[1])
12numaddrs = 1 << (32 - size)
13
14ipre = re.compile("^IP=(172\.16\.[0-9]+\.[0-9]+)/([0-9]+) *")
15
16def parseaddr(s):
17 f = s.split('.')
18 return (long(f[0]) << 24L) + \
19 (long(f[1]) << 16L) + \
20 (long(f[2]) << 8L) + \
21 long(f[3])
22
23def showaddr(a):
24 return "%d.%d.%d.%d" % ((a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff)
25
26bezet = {}
27
28(cout, cin) = popen2.popen2("cat */wleiden.conf | grep ^IP | grep 172.16\...*\/[28\|29\|30]")
29cin.close()
30for l in cout.readlines():
31 l = l[:-1]
32 match = ipre.match(l)
33 if match == None:
34 #print "'" + l + "'"
35 continue
36 if len(match.groups()) == 0:
37 continue
38 addr = parseaddr(match.group(1))
39 mask = int(match.group(2))
40 addr = addr & ~((1 << (32 - mask)) - 1)
41 bezet[addr] = 1
42
43i = 0xffffffffL
44for k in bezet.keys():
45 if k < i:
46 i = k
47
48
49i = 0xac100300
50if size == 24:
51 i = 0xac110000
52while bezet.has_key(i):
53 i = i + numaddrs
54
55print "%s/%d:" % (showaddr(i), size),
56print " en ".join([showaddr(i) for i in range(i + 1, i + numaddrs - 1)])
Note: See TracBrowser for help on using the repository browser.