2012. 12. 21. 20:22

[python 2.7] telnetlib를 이용한 telnet 접속하기
http://docs.python.org/2/library/telnetlib.html
#!/usr/bin/env python
import getpass
import sys
import telnetlib

HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
    tn.read_until("Password: ")
    tn.write(password + "\n")

tn.write("ls\n")
tn.write("exit\n")

print tn.read_all()

Posted by k1rha