ip:主机名查找失败

2024-10-02 16:30:27 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

Tags: toinimportipforinputtimeos
1条回答
网友
1楼 · 发布于 2024-10-02 16:30:27

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

您需要传递变量ip的值,以便:

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

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

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

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

相关问题 更多 >