Last change
on this file since 6823 was 6024, checked in by lodewijk, 17 years ago |
als er een om een /24 gevraagd wordt, begin dan te kijken bij 172.17.0.0 ipv
172.16.0.0
|
-
Property svn:eol-style
set to
native
|
File size:
1.2 KB
|
Rev | Line | |
---|
[4150] | 1 | # zoek de eerste vrije (== niet in een wleiden.conf gedefinieerde) interlink
|
---|
| 2 | # range
|
---|
[5283] | 3 | # lodewijk@wirelessleiden.nl
|
---|
[3130] | 4 | import popen2
|
---|
| 5 | import re
|
---|
[4150] | 6 | import sys
|
---|
[3130] | 7 |
|
---|
[4150] | 8 | size = 30
|
---|
| 9 | if len(sys.argv) > 1:
|
---|
| 10 | size = int(sys.argv[1])
|
---|
| 11 | numaddrs = 1 << (32 - size)
|
---|
| 12 |
|
---|
[4149] | 13 | ipre = re.compile("^IP=(172\.16\.[0-9]+\.[0-9]+)/([0-9]+) *")
|
---|
[3130] | 14 |
|
---|
| 15 | def parseaddr(s):
|
---|
| 16 | f = s.split('.')
|
---|
| 17 | return (long(f[0]) << 24L) + \
|
---|
| 18 | (long(f[1]) << 16L) + \
|
---|
| 19 | (long(f[2]) << 8L) + \
|
---|
| 20 | long(f[3])
|
---|
| 21 |
|
---|
| 22 | def showaddr(a):
|
---|
| 23 | return "%d.%d.%d.%d" % ((a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff)
|
---|
| 24 |
|
---|
| 25 | bezet = {}
|
---|
| 26 |
|
---|
[4162] | 27 | (cout, cin) = popen2.popen2("cat */wleiden.conf | grep ^IP | grep 172.16\...*\/[28\|29\|30]")
|
---|
[3130] | 28 | cin.close()
|
---|
| 29 | for l in cout.readlines():
|
---|
| 30 | l = l[:-1]
|
---|
| 31 | match = ipre.match(l)
|
---|
| 32 | if match == None:
|
---|
[5809] | 33 | #print "'" + l + "'"
|
---|
| 34 | continue
|
---|
| 35 | if len(match.groups()) == 0:
|
---|
| 36 | continue
|
---|
[3130] | 37 | addr = parseaddr(match.group(1))
|
---|
[4149] | 38 | mask = int(match.group(2))
|
---|
| 39 | addr = addr & ~((1 << (32 - mask)) - 1)
|
---|
[3130] | 40 | bezet[addr] = 1
|
---|
| 41 |
|
---|
| 42 | i = 0xffffffffL
|
---|
| 43 | for k in bezet.keys():
|
---|
| 44 | if k < i:
|
---|
| 45 | i = k
|
---|
| 46 |
|
---|
[6024] | 47 |
|
---|
| 48 | i = 0xac100300
|
---|
[5519] | 49 | if size == 24:
|
---|
| 50 | i = 0xac110000
|
---|
[3130] | 51 | while bezet.has_key(i):
|
---|
[4150] | 52 | i = i + numaddrs
|
---|
[3130] | 53 |
|
---|
[4150] | 54 | print "%s/%d:" % (showaddr(i), size),
|
---|
| 55 | print " en ".join([showaddr(i) for i in range(i + 1, i + numaddrs - 1)])
|
---|
Note:
See
TracBrowser
for help on using the repository browser.