使用python的telnetlib进行设备访问
import telnetlib import time def tel_connect(file_name=None,host=None,port=23): tn=telnetlib.Telnet(host,port) tn.read_until(b"Password:") f=open(file_name) lines=f.readlines() for line in lines: tn.write((line+"\n").encode("utf-8")) time.sleep(1) print(tn.read_very_eager().decode("utf-8")) tn.close() tel_connect("telnet.txt","10.98.249.12")
标签: python
发表评论: