+#!/usr/bin/env python
+# vim: set et sw=4 sts=4 :
+
+def get_campos(line):
+ r = []
+ for c in line.split('\t'):
+ r.append(c.strip('"\n'))
+ return r
+
+def parse(f):
+ hosts = {}
+ line = f.readline()
+ while line:
+ if line.startswith('"tabla de ruteo de '):
+ host = line[19:-7]
+ hosts[host] = {}
+ line = f.readline()
+ 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]
+ hosts[host]['ifaces'].append({
+ 'iface': iface,
+ 'ip': ip,
+ 'mascara': mascara,
+ 'broadcast': broadcast,
+ })
+ line = f.readline()
+ line = f.readline()
+ hosts[host]['rutas'] = []
+ while line and line.strip() <> '"--"':
+ if line.startswith('"'):
+ (red, ip, mascara, gateway, iface, metrica) = get_campos(line)
+ if not metrica: metrica = "1"
+ hosts[host]['rutas'].append({
+ 'red': red,
+ 'ip': ip,
+ 'mascara': mascara,
+ 'gateway': gateway,
+ 'iface': iface,
+ 'metrica': metrica,
+ })
+ line = f.readline()
+ line = f.readline()
+ return hosts
+
+def main(host):
+ import sys, pprint
+ #pprint.pprint(parse(sys.stdin))
+ #sys.exit(1)
+ 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
+ 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
+
+if __name__ == '__main__':
+ import sys
+ main(sys.argv[1])
+