import getpass import sys import telnetlib import time ############################################################################### user = sys.argv[1] password = sys.argv[2] HOST = sys.argv[3] ############################################################################### import struct, fcntl, os f = open("/var/lock/" + HOST, "w") fcntl.flock(f, fcntl.LOCK_EX) ############################################################################### tn = telnetlib.Telnet(HOST) tn.set_debuglevel(1) tn.expect(["Login:"],10) tn.write(user + "\n") tn.expect(["Password:"],10) tn.write(password + "\n") time.sleep(1); tn.write("enable\n"); tn.expect(["Password:"],10) tn.write(password + "\n") time.sleep(1); #tn.expect(["Password:"],10) #tn.write(password + "\n") print tn.read_very_lazy() tn.expect(["#"],10) #tn.interact() time.sleep(1) stdin = sys.stdin.read() for line in stdin.split("\n"): print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") tn.write(line + "\n") time.sleep(1) print(tn.read_until("#")) tn.write("\nquit\n")