generate_ip_range (ip.py)

Nettacker · scraping

Generates IPv4/IPv6 address ranges from CIDR blocks via netaddr, returning expanded IP lists for network targeting.

# Source: https://github.com/OWASP/Nettacker | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
import json

import netaddr
import requests


def generate_ip_range(ip_range):
    """
    IP range to CIDR and IPNetwork type

    Args:
        ip_range: IP range

    Returns:
        an array with CIDRs
    """
    if "/" in ip_range:
        return [ip.format() for ip in [cidr for cidr in netaddr.IPNetwork(ip_range)]]
    else:
        ips = []
        for generator_ip_range in [
            cidr.iter_hosts() for cidr in netaddr.iprange_to_cidrs(*ip_range.rsplit("-"))
        ]:
            for ip in generator_ip_range:
                ips.append(ip.format())
        return ips


def g

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key