[cli] fixed hostname mismatch error (#2465)

pull/2471/head
Frank Lee 2023-01-12 14:52:09 +08:00 committed by GitHub
parent c20529fe78
commit 14d9299360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -1,5 +1,5 @@
from typing import List
import socket
from typing import List
class HostInfo:
@ -35,9 +35,14 @@ class HostInfo:
if port is None:
port = 22 # no port specified, lets just use the ssh port
hostname = socket.getfqdn(hostname)
# socket.getfqdn("127.0.0.1") does not return localhost
# on some users' machines
# thus, we directly return True if hostname is locahost, 127.0.0.1 or 0.0.0.0
if hostname in ("localhost", "127.0.0.1", "0.0.0.0"):
return True
hostname = socket.getfqdn(hostname)
localhost = socket.gethostname()
localaddrs = socket.getaddrinfo(localhost, port)
targetaddrs = socket.getaddrinfo(hostname, port)