Last change
on this file since 7944 was 7936, checked in by lodewijk, 15 years ago |
herschrijf het zoeken naar IP adressen. ipv de uitvoer van grep pakken, ga
zelf over */wleiden.conf's heen. hou variabelen bij, en handel vervolgens
references naar die variabelen af als er een "IP=" voorbij komt.
|
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
File size:
1.5 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 popen2
|
---|
| 6 | import re
|
---|
[4150] | 7 | import sys
|
---|
[7936] | 8 | import glob
|
---|
[3130] | 9 |
|
---|
[4150] | 10 | size = 30
|
---|
[7325] | 11 | if len(sys.argv) < 2:
|
---|
| 12 | print "Gebruik: python getrange.py <interlink|subnet> <size>"
|
---|
| 13 | print "dus voor een /28 interlink is het 'python getrange.py interlink 28'"
|
---|
| 14 | print "en voor een /25 subnet is het 'python getrange.py subnet 25'"
|
---|
| 15 | interlink = sys.argv[1] == 'interlink'
|
---|
| 16 | size = int(sys.argv[2])
|
---|
[4150] | 17 | numaddrs = 1 << (32 - size)
|
---|
| 18 |
|
---|
[7936] | 19 | substre = re.compile("^(\$[a-zA-Z][^ =]*) ?= ?'([^']*)';")
|
---|
[3130] | 20 |
|
---|
| 21 | def parseaddr(s):
|
---|
| 22 | f = s.split('.')
|
---|
| 23 | return (long(f[0]) << 24L) + \
|
---|
| 24 | (long(f[1]) << 16L) + \
|
---|
| 25 | (long(f[2]) << 8L) + \
|
---|
| 26 | long(f[3])
|
---|
| 27 |
|
---|
| 28 | def showaddr(a):
|
---|
| 29 | return "%d.%d.%d.%d" % ((a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff)
|
---|
| 30 |
|
---|
| 31 | bezet = {}
|
---|
| 32 |
|
---|
[7936] | 33 | for fname in glob.glob("*/wleiden.conf"):
|
---|
| 34 | substs = {}
|
---|
| 35 | for l in open(fname):
|
---|
| 36 | l = l[:-1]
|
---|
| 37 | match = substre.match(l)
|
---|
| 38 | if match != None:
|
---|
| 39 | substs[match.group(1)] = match.group(2)
|
---|
| 40 | if l.startswith("IP="):
|
---|
| 41 | right = l[3:]
|
---|
| 42 | if '/' not in right:
|
---|
| 43 | addr = right
|
---|
| 44 | mask = 32
|
---|
| 45 | else:
|
---|
| 46 | addr, mask = right.split('/')
|
---|
| 47 | if addr in substs:
|
---|
| 48 | addr = substs[addr]
|
---|
| 49 | addr = parseaddr(addr)
|
---|
| 50 | mask = int(mask)
|
---|
| 51 | addr = addr & ~((1 << (32 - mask)) - 1)
|
---|
| 52 | bezet[addr] = 1
|
---|
[3130] | 53 |
|
---|
| 54 | i = 0xffffffffL
|
---|
| 55 | for k in bezet.keys():
|
---|
| 56 | if k < i:
|
---|
| 57 | i = k
|
---|
| 58 |
|
---|
[6024] | 59 |
|
---|
| 60 | i = 0xac100300
|
---|
[7325] | 61 | if not interlink:
|
---|
[5519] | 62 | i = 0xac110000
|
---|
[3130] | 63 | while bezet.has_key(i):
|
---|
[4150] | 64 | i = i + numaddrs
|
---|
[3130] | 65 |
|
---|
[4150] | 66 | print "%s/%d:" % (showaddr(i), size),
|
---|
| 67 | print " en ".join([showaddr(i) for i in range(i + 1, i + numaddrs - 1)])
|
---|
Note:
See
TracBrowser
for help on using the repository browser.