Skip to content

Commit

Permalink
Added an action for listing ips in a CIDR range
Browse files Browse the repository at this point in the history
  • Loading branch information
frikky committed Feb 21, 2024
1 parent 2fb2483 commit cec44a9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
13 changes: 13 additions & 0 deletions shuffle-tools/1.2.0/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
38 changes: 38 additions & 0 deletions shuffle-tools/1.2.0/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit cec44a9

Please sign in to comment.