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
|
Rev | Line | |
---|
[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] | 5 | import re
|
---|
[4150] | 6 | import sys
|
---|
[7936] | 7 | import glob
|
---|
[3130] | 8 |
|
---|
[4150] | 9 | size = 30
|
---|
[7325] | 10 | if len(sys.argv) < 2:
|
---|
| 11 | print "Gebruik: python getrange.py <interlink|subnet> <size>"
|
---|
[7972] | 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'"
|
---|
[7971] | 14 | exit(1)
|
---|
| 15 |
|
---|
[7325] | 16 | interlink = sys.argv[1] == 'interlink'
|
---|
| 17 | size = int(sys.argv[2])
|
---|
[4150] | 18 | numaddrs = 1 << (32 - size)
|
---|
| 19 |
|
---|
[7936] | 20 | substre = re.compile("^(\$[a-zA-Z][^ =]*) ?= ?'([^']*)';")
|
---|
[3130] | 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 |
|
---|
[7936] | 34 | for fname in glob.glob("*/wleiden.conf"):
|
---|
| 35 | substs = {}
|
---|
[7972] | 36 | lineNr = 0
|
---|
[7936] | 37 | for l in open(fname):
|
---|
[7972] | 38 | lineNr += 1
|
---|
[7936] | 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]
|
---|
[7972] | 52 | try:
|
---|
| 53 | addr = parseaddr(addr)
|
---|
| 54 | mask = int(mask)
|
---|
| 55 | addr = addr & ~((1 << (32 - mask)) - 1)
|
---|
[8188] | 56 | for i in range(0, (1 << (32 - mask))):
|
---|
| 57 | bezet[addr + i] = 1
|
---|
[7972] | 58 | except ValueError, e:
|
---|
| 59 | print "[FOUT] in bestand '%s' regel '%i': %s" % (fname, lineNr, l)
|
---|
[3130] | 60 |
|
---|
| 61 | i = 0xffffffffL
|
---|
| 62 | for k in bezet.keys():
|
---|
| 63 | if k < i:
|
---|
| 64 | i = k
|
---|
| 65 |
|
---|
[6024] | 66 | i = 0xac100300
|
---|
[7325] | 67 | if not interlink:
|
---|
[5519] | 68 | i = 0xac110000
|
---|
[8188] | 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
|
---|
[3130] | 80 |
|
---|
[4150] | 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.