usr bin python import sys telnetlib getpass newipaddr 192 168 swlogin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/usr/bin/python
import sys, telnetlib, getpass
newipaddr = '192.168.1.2'
swlogin = 'root'
swpass = getpass.getpass()
tn = telnetlib.Telnet(newipaddr)
tn.read_until("name")
tn.write(swlogin+'\n')
tn.read_until("word")
tn.write(swpass+'\n')
tn.write("ls\n")
tn.write("exit\n")
print tn.read_all()