Last change
on this file since 7999 was 7972, checked in by rick, 15 years ago |
Basic ErrorHandling and raise condition allowance and more readable usage warning
|
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
File size:
1.7 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
|
---|
5 | import re
|
---|
6 | import sys
|
---|
7 | import glob
|
---|
8 |
|
---|
9 | size = 30
|
---|
10 | if len(sys.argv) < 2:
|
---|
11 | print "Gebruik: python getrange.py <interlink|subnet> <size>"
|
---|
12 | print "\tdus voor een /28 interlink is het 'python getrange.py interlink 28'"
|
---|
13 | print "\ten voor een /25 subnet is het 'python getrange.py subnet 25'"
|
---|
14 | exit(1)
|
---|
15 |
|
---|
16 | interlink = sys.argv[1] == 'interlink'
|
---|
17 | size = int(sys.argv[2])
|
---|
18 | numaddrs = 1 << (32 - size)
|
---|
19 |
|
---|
20 | substre = re.compile("^(\$[a-zA-Z][^ =]*) ?= ?'([^']*)';")
|
---|
21 |
|
---|
22 | def parseaddr(s):
|
---|
23 | f = s.split('.')
|
---|
24 | return (long(f[0]) << 24L) + \
|
---|
25 | (long(f[1]) << 16L) + \
|
---|
26 | (long(f[2]) << 8L) + \
|
---|
27 | long(f[3])
|
---|
28 |
|
---|
29 | def showaddr(a):
|
---|
30 | return "%d.%d.%d.%d" % ((a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff)
|
---|
31 |
|
---|
32 | bezet = {}
|
---|
33 |
|
---|
34 | for fname in glob.glob("*/wleiden.conf"):
|
---|
35 | substs = {}
|
---|
36 | lineNr = 0
|
---|
37 | for l in open(fname):
|
---|
38 | lineNr += 1
|
---|
39 | l = l[:-1]
|
---|
40 | match = substre.match(l)
|
---|
41 | if match != None:
|
---|
42 | substs[match.group(1)] = match.group(2)
|
---|
43 | if l.startswith("IP="):
|
---|
44 | right = l[3:]
|
---|
45 | if '/' not in right:
|
---|
46 | addr = right
|
---|
47 | mask = 32
|
---|
48 | else:
|
---|
49 | addr, mask = right.split('/')
|
---|
50 | if addr in substs:
|
---|
51 | addr = substs[addr]
|
---|
52 | try:
|
---|
53 | addr = parseaddr(addr)
|
---|
54 | mask = int(mask)
|
---|
55 | addr = addr & ~((1 << (32 - mask)) - 1)
|
---|
56 | bezet[addr] = 1
|
---|
57 | except ValueError, e:
|
---|
58 | print "[FOUT] in bestand '%s' regel '%i': %s" % (fname, lineNr, l)
|
---|
59 |
|
---|
60 | i = 0xffffffffL
|
---|
61 | for k in bezet.keys():
|
---|
62 | if k < i:
|
---|
63 | i = k
|
---|
64 |
|
---|
65 |
|
---|
66 | i = 0xac100300
|
---|
67 | if not interlink:
|
---|
68 | i = 0xac110000
|
---|
69 | while bezet.has_key(i):
|
---|
70 | i = i + numaddrs
|
---|
71 |
|
---|
72 | print "%s/%d:" % (showaddr(i), size),
|
---|
73 | print " en ".join([showaddr(i) for i in range(i + 1, i + numaddrs - 1)])
|
---|
Note:
See
TracBrowser
for help on using the repository browser.