vRealize Orchestrator Workflow Script to Evaluate if IP Address is in CIDR
I was doing some validation of input in a vRealize Automation Service Broker Catalog item form, One of the validation is to check if a IP address is inside a specific CIDR.
The inputs are:
- cidr : string
- ipAddress: string
The Output is:
- validIp : boolean
the script looks like this:
function u(n) { return n >>> 0; } var m = cidr.match(/\d+/g); var addr32 = m.slice(0, 4).reduce(function (a, o) {return u(+a << 8) + +o;}); var mask = u(~0 << (32 - +m[4])); var start = u(addr32 & mask); // 198.162.1.0 var end = u(addr32 | ~mask); // 198.162.1.255 var m2 = ipAddress.match(/\d+/g); var ipAddr32 = m2.slice(0, 4).reduce(function (a, o) {return u(+a << 8) + +o;}); if (ipAddr32 > start && ipAddr32 < end) { validIp = true; } else { validIp = false; }
Awesome job. Thanks
could you explain to me how to use action to fetch the value of a user input? The purpose is to use the value in other variables
Hi Helton
Not sure what it is you want to do.