是编程和基础知识的新手。该代码应允许用户输入IP地址,然后打印接下来的五个IP地址。分配说明如下:编写一个python程序以读取四个数字(代表IP的四个八位字节)并打印下一个五个IP地址。您无需验证数字是否为真实的IP寻址方案。我正在寻找通过循环顺序添加。
到目前为止,我的代码是:
import ipaddress
int(ipaddress.IPv4Address('192.168.255.252'))
start_ip = ipaddress.IPv4Address('192.168.255.253')
end_ip = ipaddress.IPv4Address('192.169.0.2')
for ip_int in range(int(start_ip), int(end_ip)):
print(ipaddress.IPv4Address(ip_int))
不是应该知道IP地址,而是应该输入它,然后让它打印接下来的5个地址。非常感谢您的帮助,谢谢!
尝试:
ip = input("Input IP address:")
import ipaddress
start_ip = ipaddress.IPv4Address(int(ipaddress.IPv4Address(ip)))
end_ip = ipaddress.IPv4Address(int(ipaddress.IPv4Address(ip))+5)
for ip_int in range(int(start_ip), int(end_ip)):
print(ipaddress.IPv4Address(ip_int))
输入123.123.123.123
后的输出:
123.123.123.123
123.123.123.124
123.123.123.125
123.123.123.126
123.123.123.127