ip: Host name lookup failure



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

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

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

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

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

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

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

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

相关内容

  • 没有找到相关文章

最新更新