在Python中使用telnet获取mac地址

时间:2017-01-23 12:27:11

标签: python python-2.7 telnet mac-address

我正在尝试从stb获取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脚本运行命令时,输出格式不同。

<telnetlib.Telnet instance at 0x02760D50>
<telnetlib.Telnet instance at 0x02760DC8>
<telnetlib.Telnet instance at 0x02760EB8>
<telnetlib.Telnet instance at 0x02760FD0>
<telnetlib.Telnet instance at 0x02762120>
<telnetlib.Telnet instance at 0x02762238>
<telnetlib.Telnet instance at 0x02762350>
<telnetlib.Telnet instance at 0x02762468>

任何帮助都将不胜感激。

0 个答案:

没有答案