2 # vim: set et sw=4 sts=4 :
8 for c in line.split('\t'):
9 r.append(c.strip('"\n'))
16 if line.startswith('"tabla de ruteo de '):
20 hosts[host]['ifaces'] = []
21 while line and line.strip() <> '"red"\t"ip"\t"mascara"\t"gateway"\t"interfaz"\t"metrica"':
22 if line.startswith('"'):
23 (iface, ip, mascara, broadcast) = get_campos(line)[:4]
24 hosts[host]['ifaces'].append({
28 'broadcast': broadcast,
32 hosts[host]['rutas'] = []
33 while line and line.strip() <> '"--"':
34 if line.startswith('"'):
35 (red, ip, mascara, gateway, iface, metrica) = get_campos(line)
36 if not metrica: metrica = "1"
37 hosts[host]['rutas'].append({
50 hosts = parse(sys.stdin)
51 for iface in hosts[host]['ifaces']:
52 if not iface['iface'].startswith('ppp'):
53 print 'UP: ifconfig %(iface)s %(ip)s broadcast %(broadcast)s netmask %(mascara)s' % iface
54 os.system('ifconfig %(iface)s %(ip)s broadcast %(broadcast)s netmask %(mascara)s' % iface)
55 for ruta in hosts[host]['rutas']:
56 if ruta['metrica'] <> "0":
57 print 'UP: route add -net %(ip)s gw %(gateway)s netmask %(mascara)s dev %(iface)s metric %(metrica)s' % ruta
58 os.system('route add -net %(ip)s gw %(gateway)s netmask %(mascara)s dev %(iface)s metric %(metrica)s' % ruta)
61 hosts = parse(sys.stdin)
62 for iface in hosts[host]['ifaces']:
63 if not iface['iface'].startswith('ppp'):
64 print 'DOWN: ifconfig %(iface)s down' % iface
65 os.system('ifconfig %(iface)s down' % iface)
68 hosts = parse(sys.stdin)
69 for host in hosts.keys():
72 if __name__ == '__main__':
74 print >>sys.stderr, 'Uso: %s [up|down] host' % sys.argv[0]
76 if sys.argv[1] == 'up':
78 elif sys.argv[1] == 'down':
80 elif sys.argv[1] == 'list':