【发布时间】:2022-01-24 05:54:46
【问题描述】:
所以我从 1.1.1.0 到 1.1.1.10 范围内获取所有 ip,并使用每个 ip 单独连接到 ssh。当我运行“print(host1)”时,它给了我 ip,但是当我在 ssh.connect 中使用变量 host1 时,我收到错误“getaddrinfo() argument 1 must be string or None”,如果我将变量 host1 放入引号中我收到错误“只能将 str(不是“IPv4Address”)连接到 str”
start_ip = ipaddress.IPv4Address('1.1.1.0')
end_ip = ipaddress.IPv4Address('1.1.1.10')
for ip_int in range(int(start_ip), int(end_ip)):
host1 = ipaddress.IPv4Address(ip_int)
print(ipaddress.IPv4Address(ip_int))
print(host1)
def ssh_connect(password, code=0):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(host1, port=22, username=username, password=password, timeout=5)
【问题讨论】:
-
尝试将 'print(host1)' 语句移到 'try:' 语句下方,我的直觉是你不会得到你期望的输出。
标签: python-3.x ssh