Last change
on this file since 8223 was 8188, checked in by lodewijk, 14 years ago |
per Huub, als je zoekt naar een subnet kan het het bestaan van een kleiner
subnet over het hoofd zien. fix.
|
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
File size:
1.8 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 | for i in range(0, (1 << (32 - mask))):
|
---|
57 | bezet[addr + i] = 1
|
---|
58 | except ValueError, e:
|
---|
59 | print "[FOUT] in bestand '%s' regel '%i': %s" % (fname, lineNr, l)
|
---|
60 |
|
---|
61 | i = 0xffffffffL
|
---|
62 | for k in bezet.keys():
|
---|
63 | if k < i:
|
---|
64 | i = k
|
---|
65 |
|
---|
66 | i = 0xac100300
|
---|
67 | if not interlink:
|
---|
68 | i = 0xac110000
|
---|
69 | while 1:
|
---|
70 | while bezet.has_key(i):
|
---|
71 | i = i + numaddrs
|
---|
72 | okay = 1
|
---|
73 | for j in range(numaddrs):
|
---|
74 | if bezet.has_key(i + j):
|
---|
75 | i = i + numaddrs
|
---|
76 | okay = 0
|
---|
77 | break
|
---|
78 | if okay:
|
---|
79 | break
|
---|
80 |
|
---|
81 | print "%s/%d:" % (showaddr(i), size),
|
---|
82 | print " en ".join([showaddr(i) for i in range(i + 1, i + numaddrs - 1)])
|
---|
Note:
See
TracBrowser
for help on using the repository browser.