Skip to content

Commit cec44a9

Browse files
committed
Added an action for listing ips in a CIDR range
1 parent 2fb2483 commit cec44a9

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

shuffle-tools/1.2.0/api.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,19 @@ actions:
955955
returns:
956956
schema:
957957
type: string
958+
- name: list_cidr_ips
959+
description: Lists the IPs for a CIDR
960+
parameters:
961+
- name: cidr
962+
description: IP CIDR to check
963+
multiline: false
964+
example: "1.1.1.0/24"
965+
required: True
966+
schema:
967+
type: string
968+
returns:
969+
schema:
970+
type: string
958971
- name: cidr_ip_match
959972
description: Check if an IP is contained in a CIDR defined network
960973
parameters:

shuffle-tools/1.2.0/src/app.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,44 @@ def parse_ioc_new(self, input_string, input_type="all"):
26542654
return "Failed to parse IOC's: %s" % e
26552655

26562656
return newarray
2657+
2658+
def list_cidr_ips(self, cidr):
2659+
defaultreturn = {
2660+
"success": False,
2661+
"reason": "Invalid CIDR address"
2662+
}
2663+
2664+
if not cidr:
2665+
return defaultreturn
2666+
2667+
if "/" not in cidr:
2668+
defaultreturn["reason"] = "CIDR address must contain / (e.g. /12)"
2669+
return defaultreturn
2670+
2671+
try:
2672+
cidrnumber = int(cidr.split("/")[1])
2673+
except ValueError as e:
2674+
defaultreturn["exception"] = str(e)
2675+
return defaultreturn
2676+
2677+
if cidrnumber < 12:
2678+
defaultreturn["reason"] = "CIDR address too large. Please stay above /12"
2679+
return defaultreturn
2680+
2681+
try:
2682+
net = ipaddress.ip_network(cidr)
2683+
except ValueError as e:
2684+
defaultreturn["exception"] = str(e)
2685+
return defaultreturn
2686+
2687+
ips = [str(ip) for ip in net]
2688+
returnvalue = {
2689+
"success": True,
2690+
"amount": len(ips),
2691+
"ips": ips
2692+
}
2693+
2694+
return returnvalue
26572695

26582696

26592697
if __name__ == "__main__":

0 commit comments

Comments
 (0)