I have a script that performs a search on internet for the provided IPs range. The IPs range is provided in the format xxx.xxx.xxx.x-xxx.xxx.xxx.x and I was looking to perform a search based on a given subnet xxx.xxx.xxx.x/32/24/16/8 from a file
this is the part of the script responsible for searching web
def IPsRange(start='', end=''):
if not start and not end:
return []
if not end and start.__contains__("-"):
start, end = start.split("-")
end = end.replace("\n","")
start = int(ip_address(start).packed.hex(), 16)
end = int(ip_address(end).packed.hex(), 16)
return [ip_address(ip).exploded for ip in range(start, end)]
def ScanRange(ranges):
threads = []
for address in IPsRange(ranges):
t = Thread(
target=__СheckAddrThreaded,
args=(address,)
)
threads.append(t)
t.start()
for thread in threads:
thread.join()
How can I can a subnet instead of a IP range?
Thank you
What I have tried:
I tried
>>> import ipaddress
>>> def get_all_ips_by_subnet(subnet):
... l = [*map(str, ipaddress.IPv4Network(subnet, strict=False))]
... return l
...
>>> l = get_all_ips_by_subnet("172.17.20.30/30")
>>> l
['172.17.20.28', '172.17.20.29', '172.17.20.30', '172.17.20.31']'