How can I generate all possible IPs from a CIDR list in Python?
问题 Let's say I have a text file contains a bunch of cidr ip ranges like this: x.x.x.x/24 x.x.x.x/24 x.x.x.x/23 x.x.x.x/23 x.x.x.x/22 x.x.x.x/22 x.x.x.x/21 and goes on... How can I convert these cidr notations to all possible ip list in a new text file in Python? 回答1: If you don't need the satisfaction of writing your script from scratch, you could use the python cidrize package. 回答2: You can use netaddr for this. The code below will create a file on your disk and fill it with every ip address in