首页 > 解决方案 > 生成从 1.1.1.1 到 255.255.255.255 的所有数字

问题描述

所以我想用 Python 编写一个脚本,生成从 1.1.1.1 到 255.255.255.255 的所有数字(例如,1.1.1.1、1.1.1.2、1.1.1.3、...)我怎么能这样做呢?谢谢。

标签: python

解决方案


Python 3 具有以下ipaddress模块:

import ipaddress
for address in range(0x01010101, 0xffffffff):
    print(ipaddress.IPv4Address(address))

推荐阅读