cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
422
Views
2
Helpful
2
Replies

Splitting a string in Velocity

glsparks
Beginner
Beginner

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?

 

1 Accepted Solution

Accepted Solutions

bigevilbeard
Engager
Engager

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 c