Is there a javascript ip address library available in servicenow ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2022 07:58 AM
Hi,
I'm going to need to some work on the server side with ip addresses. It would be helpful to have a library like:
https://www.npmjs.com/package/ip-address
Is there this kind of thing already available in servicenow?
Regards,
Rick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2022 08:11 AM
Hi,
I don't think OOB any library is present.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2022 05:00 PM
There's IPAddressValidator script include. It's just calling SncIPAddressV4 class. There's also SncIPRangeV4 class. Unfortunately, there's no documentation.
Example:
var ipAddressList =['192.168.1.256', '192.168.1.1'];
for (var i=0; i<ipAddressList.length; i++) {
try {
var ipAddress = new SncIPAddressV4(ipAddressList[i]);
gs.info('ip address: ' + ipAddressList[i] + ' is valid.');
} catch (e) {
gs.info('ip address:' + ipAddressList[i] + ' is invalid. ' + e.message);
}
}
Output:
*** Script: ip address:192.168.1.256 is invalid. Address components must be between 0 and 255!
*** Script: ip address: 192.168.1.1 is valid.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2022 05:19 PM
Here are the methods of SncIPAddressV4 class.
*** Script: IPAddressClass
*** Script: addressAsBytes
*** Script: addressAsHexString
*** Script: addressAsInetAddress
*** Script: addressAsInt
*** Script: addressAsLong
*** Script: addressAsString
*** Script: class
*** Script: compareTo
*** Script: equals
*** Script: getAddressAsBytes
*** Script: getAddressAsHexString
*** Script: getAddressAsInetAddress
*** Script: getAddressAsInt
*** Script: getAddressAsLong
*** Script: getAddressAsString
*** Script: getClass
*** Script: getIPAddressClass
*** Script: hashCode
*** Script: isLinkLocalAddress
*** Script: isLocalhost
*** Script: isMulticastAddress
*** Script: isPrivateAddress
*** Script: isPublicAddress
*** Script: isReservedAddress
*** Script: isUnicastAddress
*** Script: linkLocalAddress
*** Script: localhost
*** Script: multicastAddress
*** Script: notify
*** Script: notifyAll
*** Script: privateAddress
*** Script: publicAddress
*** Script: reservedAddress
*** Script: toString
*** Script: unicastAddress
*** Script: wait
SncIPRangeV4 has the following methods:
*** Script: attributes
*** Script: beginAddress
*** Script: behavior
*** Script: class
*** Script: contains
*** Script: containsAll
*** Script: discoveryAttributes
*** Script: empty
*** Script: endAddress
*** Script: equals
*** Script: getAttributes
*** Script: getBeginAddress
*** Script: getBehavior
*** Script: getClass
*** Script: getDiscoveryAttributes
*** Script: getEndAddress
*** Script: getRangeAsString
*** Script: hashCode
*** Script: ipOrHostnameIterator
*** Script: isEmpty
*** Script: iterator
*** Script: notify
*** Script: notifyAll
*** Script: rangeAsString
*** Script: setBehavior
*** Script: setDiscoveryAttributes
*** Script: size
*** Script: splitAt
*** Script: toString
*** Script: wait
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 08:27 PM
I did some work with the OoTB functionality several years ago. If I can find the scripts I'll share here.
There are two business rules that reference SncIPAddressV4. Both provide some insight on SncIPAddressV4 functionality
- Validate IP Range [sys_id: 81804a1ec32312007bf1bea192d3ae61]
- Ensure Unique IP Address Range [sys_id: 488903f6c3d722007bf1bea192d3aef5]
SncIPAddressV4 is also referenced in several script includes. They also offer some insight on how to use it