source: genesis/tools/get-node.py@ 10252

Last change on this file since 10252 was 10252, checked in by richardvm, 14 years ago

tool to get a list of all client ip's (in range bigger then 29), based on gformat

  • Property svn:executable set to *
File size: 877 bytes
Line 
1#!/usr/bin/env python
2
3import gformat
4
5nodes = gformat.get_nodelist()
6
7def list_ips(ip):
8 addr, mask = ip.split('/')[0], ip.split('/')[1]
9
10 if int(mask) >= 29: return []
11
12 mask = 2 ** (32 - int(mask))
13 mask = int(mask)
14 addr = addr.split('.')
15 fourth = addr[3]
16 fourth = int(fourth)
17 start = fourth - (fourth % mask)
18 start = int(start)
19 end = int(start) + int(mask)
20 end = int(end)
21
22 listing = []
23 for i in range(start, end):
24 ip2 = "%s.%s.%s.%i" % (addr[0], addr[1], addr[2], i)
25 listing.append(ip2)
26
27 return listing
28
29f = open('client-ips.txt','w')
30
31for node in nodes:
32 ifaces = gformat.get_yaml(node)['interfaces'].split(',')
33 for iface in ifaces:
34 ip = gformat.get_yaml(node)['iface_%s' % iface]['ip']
35 node_short = node.replace('CNode', '').lower()
36 for client in list_ips(ip):
37 f.write("%s %s\n" % (node_short, client))
38
39f.close()
Note: See TracBrowser for help on using the repository browser.