python实现ConfigParser读取配置文件,telnetlib连接远程服务
#!/usr/bin/env python #coding:utf8 from ConfigParser import ConfigParser import telnetlib config=ConfigParser() config.read('telnet.config') username = config.get('remote','username') password = config.get('remote','password') host = config.get('remote','ip') finish = ':~$ ' tn = telnetlib.Telnet(host) #每次做一个执行结束的判断':~$' tn.read_until('login: ') tn.write(username + '\n') tn.read_until('Password: ') tn.write(password + '\n') #执行命令创建一个用户名同名的文件夹 tn.read_until(finish) tn.write('mkdir %s\n'%username) tn.read_until(finish) tn.close()
telnet.config
[remote] ip=127.0.0.1 username=username password=password
posted on 2015-10-14 22:40 ferraborghini 阅读(515) 评论(0) 编辑 收藏 举报