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, peer) = get_campos(line)[:5]
24 hosts[host]['ifaces'].append({
28 'broadcast': broadcast,
33 hosts[host]['rutas'] = []
34 while line and line.strip() <> '"--"':
35 if line.startswith('"'):
36 (red, ip, mascara, gateway, iface, metrica) = get_campos(line)
37 if not metrica: metrica = "1"
38 hosts[host]['rutas'].append({
53 for iface in hosts[host]['ifaces']:
54 if iface['iface'].startswith('ppp'):
55 print 'UP: pppd -detach crtscts lock %(ip)s:%(peer)s /dev/ttyS0' % iface
56 os.system('pppd -detach crtscts lock %(ip)s:%(peer)s /dev/ttyS0 &' % iface)
59 print 'UP: ifconfig %(iface)s %(ip)s broadcast %(broadcast)s netmask %(mascara)s' % iface
60 os.system('ifconfig %(iface)s %(ip)s broadcast %(broadcast)s netmask %(mascara)s' % iface)
62 print 'while sleep 1; do if ping -c1 %(peer)s 2>&1 > /dev/null; then break; else echo Esperando link ppp...; fi; done' % iface
63 os.system('while sleep 1; do if ping -c1 %(peer)s 2>&1 > /dev/null; then break; else echo Esperando link ppp...; fi; done' % iface)
64 for ruta in hosts[host]['rutas']:
65 if ruta['metrica'] <> "0":
66 print 'UP: route add -net %(ip)s gw %(gateway)s netmask %(mascara)s dev %(iface)s metric %(metrica)s' % ruta
67 os.system('route add -net %(ip)s gw %(gateway)s netmask %(mascara)s dev %(iface)s metric %(metrica)s' % ruta)
71 for iface in hosts[host]['ifaces']:
72 print 'DOWN: ifconfig %(iface)s down' % iface
73 if iface['iface'].startswith('ppp'):
74 os.system('killall pppd')
76 os.system('ifconfig %(iface)s down' % iface)
80 for host in hosts.keys():
83 if __name__ == '__main__':
84 fd = file('routers_labo.csv')
86 print >>sys.stderr, 'Uso: %s [up|down] host' % sys.argv[0]
88 if sys.argv[1] == 'up':
90 elif sys.argv[1] == 'down':
92 elif sys.argv[1] == 'list':