05-30-2023 07:53 AM
I'm attempting to split a user inputted string that is representing a list of comma separated IP addresses in CIDR notation. In order to determine a wildcard mask later in the script.
eg. 192.168.0.0/24,172.16.0.0/16
#set ($networks = ${networks})
#set ($octets =$networks.split('\,'))
#set ($mask = $octets)
#foreach ($net in $mask)
$net
#end
This outputs:
192.168.0.0/24
172.16.0.0/16
I'm using this currently to create a prefix list which works as expected. However i'd like to also create an ACL from the list which would require determining the Wildcard Mask.
So what I would like to achieve is a way of returning just the list of masks e.g.
24
16
Any tips on how can i achieve this?
Solved! Go to Solution.
05-30-2023 08:42 AM
Something like?
#set ($networks = ${networks})
#set ($octets = $networks.split('\,'))
#set ($masks = [])
#foreach ($net in $octets)
#set ($mask = $net.split('/')[1])
#set ($masks.add($mask))
#end
#foreach ($mask in $masks)
$mask
#end
The inputted string is 192.168.0.0/24,172.16.0.0/16, the code will print the following to the console:
24
16
05-30-2023 08:42 AM
Something like?
#set ($networks = ${networks})
#set ($octets = $networks.split('\,'))
#set ($masks = [])
#foreach ($net in $octets)
#set ($mask = $net.split('/')[1])
#set ($masks.add($mask))
#end
#foreach ($mask in $masks)
$mask
#end
The inputted string is 192.168.0.0/24,172.16.0.0/16, the code will print the following to the console:
24
16
05-31-2023 12:20 AM
Perfect well almost perfect. I had to add this to get it to work. Else it just through a syntax error. But many thanks really helped me out.
#set ($networks = ${networks})
#set ($octets = $networks.split('\,'))
#set ($masks = [])
#foreach ($net in $octets)
#set ($mask = $net.split('/')[1])
#set ($foo = $masks.add($mask))
#end
#foreach ($mask in $masks) $mask
#end
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide