Changeset 14378 in genesis
- Timestamp:
- Jul 2, 2019, 8:32:28 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/getrange.py
r13641 r14378 1 #!/usr/bin/env python 1 #!/usr/bin/env python3 2 2 # 3 3 # Zoek de eerste vrije (== niet in een wleiden.conf gedefinieerde) interlink … … 9 9 # 07/March/2012 - Rick van der Zwet <info@rickvanderzwet.nl> 10 10 # 11 import gformat 12 import glob 11 13 import re 12 14 import sys 13 import glob 14 import gformat 15 import textwrap 15 16 16 17 def parseaddr(s): 17 18 f = s.split('.') 18 return ( long(f[0]) << 24L) + \19 ( long(f[1]) << 16L) + \20 ( long(f[2]) << 8L) + \21 long(f[3])19 return (int(f[0]) << 24) + \ 20 (int(f[1]) << 16) + \ 21 (int(f[2]) << 8) + \ 22 (int(f[3])) 22 23 23 24 … … 44 45 for i in range(0, (1 << (32 - mask))): 45 46 bezet[addr + i] = 1 46 except ValueError ,e:47 print "[FOUT] in address %s node %s" % (address, node)47 except ValueError as e: 48 print("[FOUT] in address %s node %s" % (address, node)) 48 49 49 50 for node in gformat.get_hostlist(): … … 82 83 83 84 ranges = [] 84 for n in xrange(aantal):85 for n in range(aantal): 85 86 okay = False 86 87 while not okay: 87 while bezet.has_key(i):88 while i in bezet: 88 89 i = i + numaddrs 89 90 … … 91 92 okay = True 92 93 for j in range(numaddrs): 93 if bezet.has_key(i + j):94 if (i + j) in bezet: 94 95 i = i + numaddrs 95 96 okay = False … … 105 106 def main(): 106 107 if len(sys.argv) < 2: 107 print "Gebruik: %s <interlink|subnet> <grootte> [aantal]" % sys.argv[0] 108 print "Voorbeelden:" 109 print "\tVoor drie /29 interlinks - '%s interlink 29 3'" % sys.argv[0] 110 print "\tVoor een (1) /24 subnet - '%s subnet 24'" % sys.argv[0] 108 print(textwrap.dedent(''' 109 Gebruik: %(prog)s <interlink|subnet> <grootte> [aantal] 110 Voorbeelden: 111 Voor drie /29 interlinks - '%(prog)s interlink 29 3' 112 Voor een (1) /24 subnet - '%(prog)s subnet 24' 113 ''' % { 'prog': sys.argv[0] })) 111 114 exit(1) 112 115 … … 123 126 124 127 for i in ranges: 125 print "%s/%d:" % (showaddr(i), size),128 print("%s/%d: " % (showaddr(i), size), end='') 126 129 if size > 28: 127 print " en ".join([showaddr(i) for i in range(i + 1, i + numaddrs - 1)])130 print(" en ".join([showaddr(i) for i in range(i + 1, i + numaddrs - 1)])) 128 131 else: 129 print " en ".join([showaddr(i) for i in range(i + 1, i + 4)]),130 print "...",131 print " en ".join([showaddr(i) for i in range(i + numaddrs - 7, i + numaddrs - 4)])132 print(" en ".join([showaddr(i) for i in range(i + 1, i + 4)]), end='') 133 print("...", end='') 134 print(" en ".join([showaddr(i) for i in range(i + numaddrs - 7, i + numaddrs - 4)])) 132 135 133 136 if __name__ == "__main__":
Note:
See TracChangeset
for help on using the changeset viewer.