第十三节:telnetlib、redis、threading模块

telnetlib模块案例:

import telnetlib,re
class TelnetInfo():

    def telnetdo(self, host, port, command):

        tn = telnetlib.Telnet()
        try:
            tn.open(host, port, timeout=2)
        except:
            print("can not open host:%s port:%s" % (host, port))
            exit(1)
        tn.read_until(b"Username:")
        tn.write(b'admin\n\r')
        tn.read_until(b"Password:")
        tn.write(b'admin\n\r')
        tn.write(b'\n\r')
        tn.write(b'\n\r')
        tn.write(command.encode('ascii') + b'\n\r')
        tn.write(b"bye\n\r")
        ret = tn.read_all()
        tn.close()
        del tn
        return ret

tl=TelnetInfo()
data=tl.telnetdo('127.0.0.1','2555','fj')
print(data)

猜你喜欢

转载自www.cnblogs.com/sxdpython/p/12709845.html