我正在尝试从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>
任何帮助都将不胜感激。