1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| telnetlib 登录方式
import telnetlib import time password = 'Huawei@123' username = 'huawei'
tn = telnetlib.Telnet('192.168.56.100',3000)
tn.read_until(b'Username:') tn.write(username.encode('ascii') + b'\n')
tn.read_until(b'Password:') tn.write(password.encode('ascii') + b'\n')
tn.read_until(b'<LSW1>') tn.write('sys'.encode('ascii') + b'\n')
tn.read_until(b'[LSW1]') tn.write('vlan 10'.encode('ascii') + b'\n')
tn.read_until(b'[LSW1-vlan10]') tn.write('display vlan'.encode('ascii') + b'\n')
conf = tn.read_until(b'[LSW1-vlan10]').decode("ascii") print(conf)
time.sleep(1) tn.close()
|