示例代码:
import randomdef generate_random_cn_ip():# 中国大陆IP范围start_ip = "36.54.0.0"end_ip = "123.255.255.254"# 将IP地址转换为整数start_ip_num = int(start_ip.replace(".", ""))end_ip_num = int(end_ip.replace(".", ""))# 生成一个随机整数random_ip_num = random.randint(start_ip_num, end_ip_num)# 将整数转换回IP地址格式random_ip = ".".join(str(random_ip_num)[i:i + 3] for i in range(0, 12, 3))return random_ip# 生成并打印一个随机IP
print(generate_random_cn_ip())
效果展示: