【问题标题】:ip: Host name lookup failureip:主机名查找失败
【发布时间】:2021-11-14 16:31:53
【问题描述】:

这是我的代码。我的主机名查找失败。

import random
import time
import os

sec = int(input(" input time to change Ip in Sec: "))
limit = int(input('how many time do you want to change your ip: '))

ip = ".".join(map(str, (random.randint(0, 255) for _ in range(4))))
# main fuction
for _ in range(1,5):
    ip = ".".join(map(str, (random.randint(0, 255) for _ in range(4))))
    time.sleep(6)
    os.system('sudo ifconfig wlo1 down')
    os.system('sudo ifconfig wlo1 ip')
    os.system('sudo ifconfig wlo1 up')
    print('Your Current IP Address is ',ip)

这显示了错误:

input time to change Ip in Sec: 2
how many time do you want to change your ip: 3

ip: Host name lookup failure
ifconfig: --help gives usage information.
Your Current IP Address is  212.49.83.22
ip: Host name lookup failure
ifconfig: --help gives usage information.
Your Current IP Address is  199.147.166.42

【问题讨论】:

    标签: python linux system ip-address


    【解决方案1】:

    您要求ifconfig 将接口地址设置为主机名“ip”(可能无法解析),这似乎不是您想要做的。

    您需要传递变量ip 的值,因此:

    os.system('sudo ifconfig wlo1 ' + ip)
    

    或者最好是新式 f 字符串,如果你有 Python 3.6 或更高版本:

    os.system(f'sudo ifconfig wlo1 {ip}')
    

    (如果这是 Linux 系统,您可能希望使用 ip 命令而不是 ifconfig,因为后者已被弃用)

    【讨论】:

      猜你喜欢
      • 2019-11-09
      • 2020-03-08
      • 1970-01-01
      • 2021-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 2011-06-01
      相关资源
      最近更新 更多