用Python中的telnet获取mac地址

2024-09-24 06:28:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从机顶盒获取mac地址。当我在命令行上运行“ifconfig eth0 | grep HWaddr | cut-c39-55”时,我得到了正确的mac地址。在

for ip in ip_address:

    tel_con = telnetlib.Telnet(ip, port_number, time_delay)
    tel_con.read_until("login: ")
    tel_con.write(user_name + "\r\n")
    tel_con.read_until("-sh-3.2#")
    tel_con.write("ifconfig eth0 | grep HWaddr | cut -c39-55\r\n")
    mac_addresses.append(tel_con)

    print tel_con

但是,当我从python脚本运行命令时,输出的格式不同。在

^{pr2}$

任何帮助都将不胜感激。在


Tags: ipreadmac地址congrepwriteuntil