verifying if ip address is part of ipv6 network range

girishd
Tera Contributor

Hi Everyone,

 

I have been trying to check if mentioned ip addres is part of ipv6 network. I could see there is hidden class for 

SNC.IPAddress and below are its methods : 
 
*** Script: constructor
*** Script: isValid
*** Script: isV4
*** Script: isV6
*** Script: isSameVersionAs
*** Script: isLinkLocal
*** Script: isMulticast
*** Script: isRoutable
*** Script: isPublic
*** Script: isReserved
*** Script: isUnicast
*** Script: toExpanded
*** Script: isLocalhost
*** Script: getAddressClass
*** Script: getIP
*** Script: isLinkLocalAddress
*** Script: isMulticastAddress
*** Script: isPrivateAddress
*** Script: isPublicAddress
*** Script: isReservedAddress
*** Script: isUnicastAddress
*** Script: toString

does anybody have any idea how can we check ip is in range of network or not
5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@girishd 

you can use isValid function

something like this

var ipAddress = "2001:db8:3333:4444:5555:6666:7777:8888"; // Example IPv6 address

var sncIP = new SNC.IPAddress(ipAddress);

if (sncIP.isValid()) {
    gs.info("Valid IPv6 address: " + ipAddress);
} else {
    gs.info("Invalid IPv6 address: " + ipAddress);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur, 

 

i need if IP is part of IP network or not. 

 

I have already checked above mentioned methods

@girishd 

check this docs link

IPAddress - Scoped, Global 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@girishd 

you can use this OOB Class as well and use isV6()

IPAddress - Scoped, Global 

Something like this

var ipAddress = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; // Example of valid IPv6 address

if (SNC.IPAddress.isV6(ipAddress)) {
    gs.info("Valid IPv6 address: " + ipAddress);
} else {
    gs.info("Invalid IPv6 address: " + ipAddress);
}

var ipAddress1 = "2001:0db8:85a3::8A2E:037j:7334"; // Example of invalid IPv6 address

if (SNC.IPAddress.isV6(ipAddress1)) {
    gs.info("Valid IPv6 address: " + ipAddress1);
} else {
    gs.info("Invalid IPv6 address: " + ipAddress1);
}

Output:

AnkurBawiskar_0-1742996299764.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader