python3 telnet socket.gaier:[Errno 8]提供了节点名或服务名,或未知
我正在尝试通过python3脚本根据hosts.txt文件中的ip地址远程登录路由器。但是,我收到以下错误:python3 telnet socket.gaier:[Errno 8]提供了节点名或服务名,或未知,python,telnet,telnetlib,Python,Telnet,Telnetlib,我正在尝试通过python3脚本根据hosts.txt文件中的ip地址远程登录路由器。但是,我收到以下错误: $ ./telnet_group_1.py 10.1.1.1 Traceback (most recent call last): File "./telnet_group_1.py", line 23, in <module> tn = telnetlib.Telnet(host) File "/Library/Frameworks/P
$ ./telnet_group_1.py
10.1.1.1
Traceback (most recent call last):
File "./telnet_group_1.py", line 23, in <module>
tn = telnetlib.Telnet(host)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/telnetlib.py", line 209, in __init__
self.open(host, port, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/telnetlib.py", line 225, in open
self.sock = socket.create_connection((host, port), timeout)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/socket.py", line 386, in create_connection
for res in geta ddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
截至目前,hosts.txt仅包含一个条目-只是为了使其正常工作:
10.1.1.1
您想在
主机
文件的行上使用.strip()
;除此之外,还包括换行符:
for h in hosts:
tn = telnetlib.Telnet(h.strip())
@谢谢你。现在真是魅力四射!
for h in hosts:
tn = telnetlib.Telnet(h.strip())