diff --git a/shuffle-tools/1.2.0/api.yaml b/shuffle-tools/1.2.0/api.yaml index cfa1a55b..66704dd8 100644 --- a/shuffle-tools/1.2.0/api.yaml +++ b/shuffle-tools/1.2.0/api.yaml @@ -955,6 +955,19 @@ actions: returns: schema: type: string + - name: list_cidr_ips + description: Lists the IPs for a CIDR + parameters: + - name: cidr + description: IP CIDR to check + multiline: false + example: "1.1.1.0/24" + required: True + schema: + type: string + returns: + schema: + type: string - name: cidr_ip_match description: Check if an IP is contained in a CIDR defined network parameters: diff --git a/shuffle-tools/1.2.0/src/app.py b/shuffle-tools/1.2.0/src/app.py index 03019ed7..2708309c 100644 --- a/shuffle-tools/1.2.0/src/app.py +++ b/shuffle-tools/1.2.0/src/app.py @@ -2654,6 +2654,44 @@ def parse_ioc_new(self, input_string, input_type="all"): return "Failed to parse IOC's: %s" % e return newarray + + def list_cidr_ips(self, cidr): + defaultreturn = { + "success": False, + "reason": "Invalid CIDR address" + } + + if not cidr: + return defaultreturn + + if "/" not in cidr: + defaultreturn["reason"] = "CIDR address must contain / (e.g. /12)" + return defaultreturn + + try: + cidrnumber = int(cidr.split("/")[1]) + except ValueError as e: + defaultreturn["exception"] = str(e) + return defaultreturn + + if cidrnumber < 12: + defaultreturn["reason"] = "CIDR address too large. Please stay above /12" + return defaultreturn + + try: + net = ipaddress.ip_network(cidr) + except ValueError as e: + defaultreturn["exception"] = str(e) + return defaultreturn + + ips = [str(ip) for ip in net] + returnvalue = { + "success": True, + "amount": len(ips), + "ips": ips + } + + return returnvalue if __name__ == "__main__":