下面的程序(telnetClient.py)登录telnet服务器,执行ls命令然后退出:
import telnetlib HOST = "192.168.1.178" #user = raw_input("Enter your remote account: ") #password = getpass.getpass() user = "user" password = "000" tn = telnetlib.Telnet(HOST) tn.read_until("ogin: ") tn.write(user + "\n") if password: tn.read_until("assword: ") tn.write(password + "\n") tn.write("ls\n") tn.write("exit\n") print tn.read_all()
下面是分别用python和jython运行这个脚本的命令:
python telnetClient.py
java -jar f:\warez\dev\Jython\jython-standalone-2.5.3.jar telnetClient.py
在Jython的3个下载包中,jython-standalone-2.5.3.jar是比较portable的,不需要预处理jdk(jython-2.5.3.jar),不需要安装(jython-installer-2.5.3.jar)。