From: Leandro Lucarella Date: Wed, 6 Jul 2005 04:20:38 +0000 (+0000) Subject: Manejo de ppp y se toma config de archivo en vez de stdin. X-Git-Tag: svn_import~26 X-Git-Url: https://git.llucax.com/z.facultad/75.43/tp2.git/commitdiff_plain/00dfdc2ac6b61b92560a9ed11a090125d03aaec9?ds=sidebyside Manejo de ppp y se toma config de archivo en vez de stdin. --- diff --git a/makeroute b/makeroute index 0c00402..2316394 100755 --- a/makeroute +++ b/makeroute @@ -20,12 +20,13 @@ def parse(f): hosts[host]['ifaces'] = [] while line and line.strip() <> '"red"\t"ip"\t"mascara"\t"gateway"\t"interfaz"\t"metrica"': if line.startswith('"'): - (iface, ip, mascara, broadcast) = get_campos(line)[:4] + (iface, ip, mascara, broadcast, peer) = get_campos(line)[:5] hosts[host]['ifaces'].append({ 'iface': iface, 'ip': ip, 'mascara': mascara, 'broadcast': broadcast, + 'peer': peer, }) line = f.readline() line = f.readline() @@ -46,37 +47,48 @@ def parse(f): line = f.readline() return hosts -def up(host): - hosts = parse(sys.stdin) +def up(host, fd): + hosts = parse(fd) + ppp = 0 for iface in hosts[host]['ifaces']: - if not iface['iface'].startswith('ppp'): + if iface['iface'].startswith('ppp'): + print 'UP: pppd -detach crtscts lock %(ip)s:%(peer)s /dev/ttyS0' % iface + os.system('pppd -detach crtscts lock %(ip)s:%(peer)s /dev/ttyS0 &' % iface) + ppp = 1 + else: print 'UP: ifconfig %(iface)s %(ip)s broadcast %(broadcast)s netmask %(mascara)s' % iface os.system('ifconfig %(iface)s %(ip)s broadcast %(broadcast)s netmask %(mascara)s' % iface) + if ppp: + print 'while sleep 1; do if ping -c1 %(peer)s 2>&1 > /dev/null; then break; else echo Esperando link ppp...; fi; done' % iface + 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) for ruta in hosts[host]['rutas']: if ruta['metrica'] <> "0": print 'UP: route add -net %(ip)s gw %(gateway)s netmask %(mascara)s dev %(iface)s metric %(metrica)s' % ruta os.system('route add -net %(ip)s gw %(gateway)s netmask %(mascara)s dev %(iface)s metric %(metrica)s' % ruta) -def down(host): - hosts = parse(sys.stdin) +def down(host, fd): + hosts = parse(fd) for iface in hosts[host]['ifaces']: - if not iface['iface'].startswith('ppp'): - print 'DOWN: ifconfig %(iface)s down' % iface + print 'DOWN: ifconfig %(iface)s down' % iface + if iface['iface'].startswith('ppp'): + os.system('killall pppd') + else: os.system('ifconfig %(iface)s down' % iface) -def list(): - hosts = parse(sys.stdin) +def list(fd): + hosts = parse(fd) for host in hosts.keys(): print host if __name__ == '__main__': + fd = file('routers_labo.csv') if len(sys.argv) < 2: print >>sys.stderr, 'Uso: %s [up|down] host' % sys.argv[0] sys.exit(1) if sys.argv[1] == 'up': - up(sys.argv[2]) + up(sys.argv[2], fd) elif sys.argv[1] == 'down': - down(sys.argv[2]) + down(sys.argv[2], fd) elif sys.argv[1] == 'list': - list() + list(fd)