import telnetlib debugging = 0 rcfile = None myfile=open('info.txt','r') filecontent=myfile.read().split('#') for perhost in filecontent: usage=perhost.split(';') telnet_host=usage[0].split(':')[1] telnet_userid = usage[1].split(':')[1] telnet_passwd =usage[2].split(':')[1] telnet_port = usage[3].split(':')[1] telnet_cmd=usage[4].split(':')[1] print telnet_host,telnet_userid ,telnet_passwd ,telnet_port ,telnet_cmd tn = telnetlib.Telnet() tn.set_debuglevel(debugging) tn.open(telnet_host, telnet_port) tn.read_until("/n") tn.write(telnet_userid + "/n/r") tn.read_until("/n") tn.write(telnet_passwd + "/r") tn.interact() tn.close() host:127.0.0.1;port:23;user:root;pwd:root; cmd:hello;cmd:byebye; # host:127.0.0.2;port:23;user:zwh;pwd:zwh cmd:hello;cmd:zwh;
python telnet
最新推荐文章于 2024-09-12 16:12:09 发布
本文介绍了一种通过Python的Telnet库批量读取配置文件并执行远程命令的方法。该方法利用配置文件中的主机地址、端口、用户名、密码及命令,实现自动化远程操作。
1251

被折叠的 条评论
为什么被折叠?



