Last change
on this file since 7265 was 7089, checked in by rick, 16 years ago |
Beeing lacy, saves me from typing python getrange.py, but use ./getrange.py instead
|
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
File size:
1.2 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
|
---|
[3130] | 8 |
|
---|
[4150] | 9 | size = 30
|
---|
| 10 | if len(sys.argv) > 1:
|
---|
| 11 | size = int(sys.argv[1])
|
---|
| 12 | numaddrs = 1 << (32 - size)
|
---|
| 13 |
|
---|
[4149] | 14 | ipre = re.compile("^IP=(172\.16\.[0-9]+\.[0-9]+)/([0-9]+) *")
|
---|
[3130] | 15 |
|
---|
| 16 | def parseaddr(s):
|
---|
| 17 | f = s.split('.')
|
---|
| 18 | return (long(f[0]) << 24L) + \
|
---|
| 19 | (long(f[1]) << 16L) + \
|
---|
| 20 | (long(f[2]) << 8L) + \
|
---|
| 21 | long(f[3])
|
---|
| 22 |
|
---|
| 23 | def showaddr(a):
|
---|
| 24 | return "%d.%d.%d.%d" % ((a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff)
|
---|
| 25 |
|
---|
| 26 | bezet = {}
|
---|
| 27 |
|
---|
[4162] | 28 | (cout, cin) = popen2.popen2("cat */wleiden.conf | grep ^IP | grep 172.16\...*\/[28\|29\|30]")
|
---|
[3130] | 29 | cin.close()
|
---|
| 30 | for l in cout.readlines():
|
---|
| 31 | l = l[:-1]
|
---|
| 32 | match = ipre.match(l)
|
---|
| 33 | if match == None:
|
---|
[5809] | 34 | #print "'" + l + "'"
|
---|
| 35 | continue
|
---|
| 36 | if len(match.groups()) == 0:
|
---|
| 37 | continue
|
---|
[3130] | 38 | addr = parseaddr(match.group(1))
|
---|
[4149] | 39 | mask = int(match.group(2))
|
---|
| 40 | addr = addr & ~((1 << (32 - mask)) - 1)
|
---|
[3130] | 41 | bezet[addr] = 1
|
---|
| 42 |
|
---|
| 43 | i = 0xffffffffL
|
---|
| 44 | for k in bezet.keys():
|
---|
| 45 | if k < i:
|
---|
| 46 | i = k
|
---|
| 47 |
|
---|
[6024] | 48 |
|
---|
| 49 | i = 0xac100300
|
---|
[5519] | 50 | if size == 24:
|
---|
| 51 | i = 0xac110000
|
---|
[3130] | 52 | while bezet.has_key(i):
|
---|
[4150] | 53 | i = i + numaddrs
|
---|
[3130] | 54 |
|
---|
[4150] | 55 | print "%s/%d:" % (showaddr(i), size),
|
---|
| 56 | print " en ".join([showaddr(i) for i in range(i + 1, i + numaddrs - 1)])
|
---|
Note:
See
TracBrowser
for help on using the repository browser.