#!/usr/bin/python # usage script.py # Any commands which may be typed at the console of the router may be placed in # this script. Typical uses are to change the passwords on a set of routers, # to change snmp community names, to gather the version information # for an upgrade # (show cont mci, show cont cbus, show cont tok, show hard). # # The list of routers should be contained in a file, one router to a line, or it # may be typed in from the command line (end list with ctrl-d). # import telnetlib def doStuff(host, passwd): tn = telnetlib.Telnet(host) tn.read_until("Password: ") tn.write(passwd + "\n") tn.write("term len 0\n") tn.write("show ip arp\n") tn.write("show mac-address-table\n") tn.write("quit\n") print tn.read_all() for line in file('router.list'): (host, passwd) = line.strip().split() doStuff(host, passwd)