X-Git-Url: https://git.llucax.com/z.facultad/75.43/tp2.git/blobdiff_plain/549744ae7e50106cc84606c7b7fb1750c98a4ceb..d64709ced5f38a5006dfba43e51038704b594acf:/makeroute?ds=inline diff --git a/makeroute b/makeroute index 09072bc..0c00402 100755 --- a/makeroute +++ b/makeroute @@ -1,6 +1,8 @@ #!/usr/bin/env python # vim: set et sw=4 sts=4 : +import sys, os + def get_campos(line): r = [] for c in line.split('\t'): @@ -44,19 +46,37 @@ def parse(f): line = f.readline() return hosts -def main(host): - import sys, pprint - #pprint.pprint(parse(sys.stdin)) - #sys.exit(1) +def up(host): hosts = parse(sys.stdin) for iface in hosts[host]['ifaces']: if not iface['iface'].startswith('ppp'): - print 'ifconfig %(iface)s %(ip)s broadcast %(broadcast)s netmask %(mascara)s' % iface + 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) for ruta in hosts[host]['rutas']: if ruta['metrica'] <> "0": - print 'route add -net %(ip)s gw %(gateway)s netmask %(mascara)s dev %(iface)s metric %(metrica)s' % ruta + 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) + for iface in hosts[host]['ifaces']: + if not iface['iface'].startswith('ppp'): + print 'DOWN: ifconfig %(iface)s down' % iface + os.system('ifconfig %(iface)s down' % iface) + +def list(): + hosts = parse(sys.stdin) + for host in hosts.keys(): + print host if __name__ == '__main__': - import sys - main(sys.argv[1]) + 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]) + elif sys.argv[1] == 'down': + down(sys.argv[2]) + elif sys.argv[1] == 'list': + list()