王者归来的华哥

华哥随笔记-记录生活点点滴滴

使用python进行telnet登录并执行命令

 

'''
Author: 20004@163.com
Date: 2022-07-26 14:42:41
LastEditors: error: git config user.name && git config user.email & please set dead value or install git
LastEditTime: 2022-07-27 01:21:08
FilePath: \PythonCode\百度下拉词\网络技术\telnet.py
'''
from telnetlib import Telnet
hostname='192.168.56.2'
password='123456'
 
tn=Telnet(hostname) 
tn.read_until(b'Password:') 
tn.write(password.encode('ascii') +b"\n") 
print(tn.read_until(b'<R1>').decode('ascii')) 
tn.write(b'dis ip int b' + b'\n') 
print(tn.read_until(b'<R1>').decode('ascii')) 
tn.write(b'dis arp' + b'\n') 
print(tn.read_until(b'<R1>').decode('ascii')) 
tn.close()

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注