{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":828,"path":"api-reference/server-api-reference/IPAddressAPIBoth.md","title":"IPAddress - Scoped, Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# IPAddress - Scoped, Global\n\nThe IPAddress API provides methods that enable you to check for various states of a specified IP address, such as whether it is routable, unicast, multicast, public, or reserved. It also enables you to get the canonical \\(shortened/standard\\) and expanded forms of an IP address.\n\nAccess the global IPAddress class and its associated methods in the `SNC` global namespace.\n\nIn this API, some of the methods are static and some are non-static. The [isV4\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/IPAddressAPIBoth.md) and [isV6\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/IPAddressAPIBoth.md) methods provide both static and non-static implementations. The benefit of the non-static methods is that you don't have to call the [IPAddress\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/IPAddressAPIBoth.md) method to instantiate an IPAddress object.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## IPAddress - IPAddress\\(String ipAddress\\)\n\nInstantiates an IPAddress object for the specified IP address.\n\n|Name|Type|Description|\n|----|----|-----------|\n|ipAddress|String|IP address for which to create the IPAddress object.|\n\nThe following code example shows how to call the IPAddress constructor when calling a non-static IPAddress method.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(\"SYS_ID\");\n\n  var ip = grDiscover.getValue('network_ip');\n  var ip2 = gs.getSession().getClientIP().toString();\n  gs.info(\"ip address 1: \" + ip);\n  gs.info(\"ip address 2: \" + ip2);\n  gs.info(\"ip address 1 is routable?: \" + new SNC.IPAddress(ip).isRoutable());\n  gs.info(\"ip address 2 is routable?: \" + new SNC.IPAddress(ip2).isRoutable());\n}\n```\n\n## IPAddress - canonicalize\\(String ipAddress\\)\n\nReturns the canonical \\(shortened/standard\\) form of the specified IP address by removing any zero padding from the address.\n\nFor example, the canonical form of the IPv6 address \"0000:0000:0000:0000:0000:0000:0000:0001\" is \"::1\". The canonical form of the IPv4 address \"192.168.001.002\" is \"192.268.1.2\".\n\n**Note:** This is a static method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|ipAddress|String or Object|IP address to canonicalize or a scoped IPAddress object that contains the IP address.|\n\n|Type|Description|\n|----|-----------|\n|String|Canonicalized \\(shortened/standardized\\) IP address.|\n\nThe following example shows how to use the scoped version of this method to canonicalize an IPv6 IP address.\n\n```\nfunction() {\n  var grCMDB = new GlideRecord('cmdb_ci');\n  grCMDB.get(\"SYS_ID\");\n  var ip = grCMDB.getValue('ip_address');\n  gs.info(\"ip address: \" + ip);\n  gs.info(\"canonicalized ip: \" + SNC.IPAddress.canonicalize(ip));\n}\n```\n\nOutput:\n\n```\nip address: 0000:0000:0000:0000:0000:0000:0000:0001\ncanonicalized ip: ::1\n```\n\n## IPAddress - getExpanded\\(String ipAddress\\)\n\nReturns the expanded form of the specified IP address\n\nFor example, the expanded form of the IPv6 address \"::1\" is \"0000:0000:0000:0000:0000:0000:0000:0001\". The expanded form of the IPv4 address \"192.268.1.2\" is \"192.168.001.002\".\n\n**Note:** This is a static method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|ipAddress|String|IP address to expand.|\n\n|Type|Description|\n|----|-----------|\n|String|Expanded IP address.|\n\nThe following example shows how to use the scoped version of this method to expand an IPv6 IP address.\n\n```\nfunction() {\n  var grCMDB = new GlideRecord('cmdb_ci');\n  grCMDB.get(SYS_ID);\n  var ip = grCMDB.getValue('ip_address');\n  gs.info(\"ip address: \" + ip);\n  gs.info(\"expanded ip: \" + SNC.IPAddress.getExpanded(ip));\n}\n```\n\nOutput:\n\n```\nip address: ::1\nexpanded ip: 0000:0000:0000:0000:0000:0000:0000:0001\n```\n\n## IPAddress - isLinkLocal\\(\\)\n\nDetermines whether the specified IPAddress object is a link-local IP address.\n\nFor further information on link-local IP addresses see [RFC 3927](https://datatracker.ietf.org/doc/html/rfc3927) and [RFC 4291](https://datatracker.ietf.org/doc/html/rfc4291).\n\n**Note:** This is a non-static method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_gyr_mg4_htb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the IP address object is a link-local address.\n\n Valid values:\n\n-   true: IP address is a link-local address.\n-   false: IP address is not a link-local address.\n\n</td></tr></tbody>\n</table>The following code example shows how to use the scoped version of this method to check if the IP addresses in a record in the Discovery IP Ranges \\[discovery\\_range\\_item\\] table are link-local addresses.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(\"SYS_ID\");\n\n  var ip = grDiscover.getValue('network_ip');\n  var start_ip = grDiscover.getValue('start_ip_address');\n  gs.info(\"ip address 1: \" + ip);\n  gs.info(\"ip address 2: \" + start_ip);\n  gs.info(\"ip address 1 is link local?: \" + new SNC.IPAddress(ip).isLinkLocal());\n  gs.info(\"ip address 2 is link local?: \" + new SNC.IPAddress(start_ip).isLinkLocal());\n}\n```\n\nOutput:\n\n```\nip address 1: ::1\nip address 2: fe80:1::1\nip address 1 is link local?: false\nip address 2 is link local?: true\n```\n\n## IPAddress - isLocalhost\\(\\)\n\nDetermines whether the specified IPAddress object is the loopback IP address.\n\nFor additional information on the loopback IP address, see [IANA IPv4 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml) and [IANA IPv6 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xml).\n\n**Note:** This is a non-static method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_lgl_g3l_3tb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the IP address object is the loopback IP address.\n\n Valid values:\n\n-   true: IP address is the loopback IP address.\n-   false: IP address is not the loopback IP address.\n\n</td></tr></tbody>\n</table>The following code example shows how to use the scoped version of this method to check if the IP addresses in a record in the Discovery IP Ranges \\[discovery\\_range\\_item\\] table are the loopback IP address.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(\"SYS_ID\");\n  var ip = grDiscover.getValue('network_ip');\n  var start_ip = grDiscover.getValue('start_ip_address');\n  gs.info(\"ip address 1: \" + ip);\n  gs.info(\"ip address 2: \" + start_ip);\n  gs.info(\"ip address 1 is localhost?: \" + new SNC.IPAddress(ip).isLocalhost());\n  gs.info(\"ip address 2 is localhost?: \" + new SNC.IPAddress(ip2).isLocalhost());\n}\n```\n\nOutput:\n\n```\nip address 1: 127.0.0.1\nip address 2: <current user's public IP Address>\nip address 1 is localhost?: true\nip address 2 is localhost?: false\n```\n\n## IPAddress - isMulticast\\(\\)\n\nDetermines whether the specified IPAddress object is a multicast IP address.\n\nFor further information on multicast IP addresses see [RFC 2365](https://datatracker.ietf.org/doc/html/rfc2365) and [RFC 3306](https://datatracker.ietf.org/doc/html/rfc3306).\n\n**Note:** This is a non-static method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_rww_sh4_htb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the IP address object is a multicast address.\n\n Valid values:\n\n-   true: IP address is a multicast address.\n-   false: IP address is not a multicast address.\n\n</td></tr></tbody>\n</table>The following code example shows how to use the scoped version of this method to check if the IP addresses in a record in the Discovery IP Ranges \\[discovery\\_range\\_item\\] table are multicast addresses.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(\"SYS_ID\");\n  var ip = grDiscover.getValue('network_ip');\n  var start_ip = grDiscover.getValue('start_ip_address');\n  gs.info(\"ip address 1: \" + ip);\n  gs.info(\"ip address 2: \" + start_ip);\n  gs.info(\"ip address 1 is multicast?: \" + new SNC.IPAddress(ip).isMulticast());\n  gs.info(\"ip address 2 is multicast?: \" + new SNC.IPAddress(start_ip).isMulticast());\n}\n```\n\nOutput:\n\n```\nip address 1: ::1\nip address 2: 224.0.0.22\nip address 1 is multicast?: false\nip address 2 is multicast?: true\n```\n\n## IPAddress - isPublic\\(\\)\n\nDetermines whether the specified IPAddress object is a public IP address. An IP address is considered public if it is routable, and it is not a reserved address.\n\n**Note:** This is a non-static method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_m2f_22l_3tb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the IP address object is a public address.\n\n Valid values:\n\n-   true: IP address is a public address.\n-   false: IP address is not a public address.\n\n</td></tr></tbody>\n</table>The following code example shows how to use the scoped version of this method to check if the IP addresses in a record in the Discovery IP Ranges \\[discovery\\_range\\_item\\] table are public addresses.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(\"SYS_ID\");\n  var ip = grDiscover.getValue('network_ip');\n  var ip2 = gs.getSession().getClientIP().toString();\n  gs.info(\"ip address 1: \" + ip);\n  gs.info(\"ip address 2: \" + ip2);\n  gs.info(\"ip address 1 is public?: \" + new SNC.IPAddress(ip).isPublic());\n  gs.info(\"ip address 2 is public?: \" + new SNC.IPAddress(ip2).isPublic());\n}\n```\n\nOutput:\n\n```\nip address 1: 2001:1::1\nip address 2: <current user's public IP Address>\nip address 1 is public?: false\nip address 2 is public?: true\n```\n\n## IPAddress - isReserved\\(\\)\n\nDetermines whether the specified IPAddress object is a reserved IP address.\n\nFor additional information on reserved IP addresses, see [IANA IPv4 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml) and [IANA IPv6 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xml).\n\n**Note:** This is a non-static method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_mpw_ffl_3tb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the IP address object is a reserved address.\n\n Valid values:\n\n-   true: IP address is a reserved address.\n-   false: IP address is not a reserved address.\n\n</td></tr></tbody>\n</table>The following code example shows how to use the scoped version of this method to check if the IP addresses in a record in the Discovery IP Ranges \\[discovery\\_range\\_item\\] table are reserved addresses.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(\"SYS_ID\");\n  var ip = grDiscover.getValue('network_ip');\n  var ip2 = gs.getSession().getClientIP().toString();\n  gs.info(\"ip address 1: \" + ip);\n  gs.info(\"ip address 2: \" + ip2);\n  gs.info(\"ip address 1 is reserved?: \" + new SNC.IPAddress(ip).isReserved());\n  gs.info(\"ip address 2 is reserved?: \" + new SNC.IPAddress(ip2).isReserved());\n}\n```\n\nOutput:\n\n```\nip address 1: 2001:1::1\nip address 2: <current user's public IP Address>\nip address 1 is reserved?: true\nip address 2 is reserved?: false\n```\n\n## IPAddress - isRoutable\\(\\)\n\nDetermines whether the specified IPAddress object is a routable IP address.\n\nAn IP Address is considered to be routable if it is not a private address, a link-local address, or the loopback address. For additional information on private addresses, see [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) and [RFC 4193](https://datatracker.ietf.org/doc/html/rfc4193).\n\n**Note:** This is a non-static method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_qv3_m34_htb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the IP address object is a routable address.\n\n Valid values:\n\n-   true: IP address is a routable address.\n-   false: IP address is not a routable address.\n\n</td></tr></tbody>\n</table>The following code example shows how to use the scoped version of this method to check if the IP addresses in a record in the Discovery IP Ranges \\[discovery\\_range\\_item\\] table are routable addresses.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(\"SYS_ID\");\n  var ip = grDiscover.getValue('network_ip');\n  var ip2 = gs.getSession().getClientIP().toString();\n  gs.info(\"ip address 1: \" + ip);\n  gs.info(\"ip address 2: \" + ip2);\n  gs.info(\"ip address 1 is routable?: \" + new SNC.IPAddress(ip).isRoutable());\n  gs.info(\"ip address 2 is routable?: \" + new SNC.IPAddress(ip2).isRoutable());\n}\n```\n\nOutput:\n\n```\nip address 1: ::1\nip address 2: <current user's public IP Address>\nip address 1 is routable?: false\nip address 2 is routable?: true\n```\n\n## IPAddress - isSameVersionAs\\(String ipAddress\\)\n\nDetermines whether the passed IPAddress object is the is the same version, IPv4 or IPv6, as the specified IP address.\n\n**Note:** This is a non-static method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|ipAddress|String|IP address to check against the IP address in the passed IPAddress object.|\n\n<table id=\"table_y2x_4f4_htb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the specified IP address is the same version as that in the IPAddress object.\n\n Valid values:\n\n-   true: IP address version is the same.\n-   false: IP address version is different.\n\n</td></tr></tbody>\n</table>The following code example shows how to use the scoped version of this method to compare whether various IP address are the same version \\(IPv4 or IPv6\\).\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(\"SYS_ID\");\n  var ip = grDiscover.getValue('network_ip');\n  var start_ip = grDiscover.getValue('start_ip_address');\n  var end_ip = grDiscover.getValue('end_ip_address');\n  gs.info(\"ip address 1: \"+ ip);\n  gs.info(\"ip address 2: \" + start_ip);\n  gs.info(\"ip address 3: \" + end_ip);\n  var ip1 = new SNC.IPAddress(ip);\n  var ip2 = new SNC.IPAddress(start_ip);\n  var ip3 = new SNC.IPAddress(end_ip);\n  gs.info(\"ip address 1 is same version as ip address 2?: \" + ip1.isSameVersionAs(ip2));\n  gs.info(\"ip address 1 is same version as itself?: \" + ip1.isSameVersionAs(ip1));\n  gs.info(\"ip address 2 is same version as ip address 3?: \" + ip2.isSameVersionAs(ip3));\n}\n```\n\nOutput:\n\n```\nip address 1: 192.168.0.1\nip address 2: ::2\nip address 3: ::3\nip address 1 is same version as ip address 2?: false\nip address 1 is same version as itself?: true\nip address 2 is same version as ip address 3?: true\n```\n\n## IPAddress - isUnicast\\(\\)\n\nDetermines whether the specified IPAddress object is a unicast IP address.\n\nA unicast address is effectively an address that is not multicast.\n\n**Note:** This is a non-static method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_al3_bhl_3tb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the IP address object is a unicast address.\n\n Valid values:\n\n-   true: IP address is a unicast address.\n-   false: IP address is not a unicast address.\n\n</td></tr></tbody>\n</table>The following code example shows how to use the scoped version of this method to check if the IP addresses in a record in the Discovery IP Ranges \\[discovery\\_range\\_item\\] table are unicast addresses.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(\"SYS_ID\");\n  var ip = grDiscover.getValue('network_ip');\n  var start_ip = grDiscover.getValue('start_ip_address');\n  gs.info(\"ip address 1: \" + ip);\n  gs.info(\"ip address 2: \" + start_ip);\n  gs.info(\"ip address 1 is unicast?: \" + new SNC.IPAddress(ip).isUnicast());\n  gs.info(\"ip address 2 is unicast?: \" + new SNC.IPAddress(ip2).isUnicast());\n}\n```\n\nOutput:\n\n```\nip address 1: 224.0.0.22\nip address 2: <current user's public IP Address>\nip address 1 is unicast?: false\nip address 2 is unicast?: true\n```\n\n## IPAddress - isV4\\(String ipAddress\\)\n\nDetermines whether the specified IP address is a valid IPv4 address.\n\nThis method has both static and non-static implementations. The way in which you call the two method types is slightly different. For the non-static implementation you don't need to first instantiate an IPAddress object and you pass the IP address in the IPAddress class reference. Both return the same response.\n\n<table id=\"table_hrb_3gn_htb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nipAddress\n\n</td><td>\n\nString\n\n</td><td>\n\nIP address to validate.For the non-static implementation, the IP address is passed in the IPAddress class reference instead of the method call.\n\n For example `New SNC.IPAddress(\"::1\").isV4();`.\n\n</td></tr></tbody>\n</table><table id=\"table_irb_3gn_htb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the specified IP address is a valid IPv4 address.\n\n Valid values:\n\n-   true: IP address is valid.\n-   false: IP address is invalid.\n\n</td></tr></tbody>\n</table>The following example shows how to use the scoped static version of this method to verify whether IP addresses in a record in the Discovery IP Ranges \\[discovery\\_range\\_item\\] table are valid IPv4 addresses.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(\"SYS_ID\");\n  var ip = grDiscover.getValue('network_ip');\n  var start_ip = grDiscover.getValue('start_ip_address');\n  gs.info(\"ip address 1: \" + ip);\n  gs.info(\"ip address 2: \" + start_ip);\n  gs.info(\"ip address 1 is v4?: \" + SNC.IPAddress.isV4(ip));\n  gs.info((\"ip address 2 is v4?: \" + SNC.IPAddress.isV4(start_ip));\n}\n```\n\nOutput:\n\n```\nip address 1: 192.168.0.1\nip address 2: ::2\nip address 1 is v4?: true\nip address 2 is v4?: false\n```\n\nThe following example shows how to use the non-static version of this method to verify whether IP addresses in a record in the Discovery IP Ranges \\[discovery\\_range\\_item\\] table are valid IPv4 addresses.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(\"SYS_ID\");\n  var ip = grDiscover.getValue('network_ip');\n  var start_ip = grDiscover.getValue('start_ip_address');\n  gs.info(\"ip address 1: \" + ip);\n  gs.info(\"ip address 2: \" + start_ip);\n  gs.info(\"ip address 1 is v4?: \" + new SNC.IPAddress(ip).isV4());\n  gs.info(\"ip address 2 is v4?: \" + new SNC.IPAddress(start_ip).isV4());\n}\n```\n\nOutput:\n\n```\nip address 1: 192.168.0.1\nip address 2: ::2\nip address 1 is v4?: true\nip address 2 is v4?: false\n```\n\n## IPAddress - isV6\\(String ipAddress\\)\n\nDetermines whether the specified IP address is a valid IPv6 address.\n\nThis method has both static and non-static implementations. The way in which you call the two method types is slightly different. For the non-static implementation you don't need to first instantiate an IPAddress object and you pass the IP address in the IPAddress class reference. Both return the same response.\n\n<table id=\"table_nkk_sgn_htb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nipAddress\n\n</td><td>\n\nString\n\n</td><td>\n\nIP address to validate. For the non-static implementation, the IP address is passed in the IPAddress class reference instead of the method call.\n\n For example `New SNC.IPAddress(\"::1\").isV6();`.\n\n</td></tr></tbody>\n</table><table id=\"table_okk_sgn_htb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the specified IP address is a valid IPv6 address.\n\n Valid values:\n\n-   true: IP address is valid.\n-   false: IP address is invalid.\n\n</td></tr></tbody>\n</table>The following example shows how to use the scoped static version of this method to verify whether IP addresses in a record in the Discovery IP Ranges \\[discovery\\_range\\_item\\] table are valid IPv6 addresses.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(SYS_ID);\n  var ip = grDiscover.getValue('network_ip');\n  var start_ip = grDiscover.getValue('start_ip_address');\n  gs.info(\"ip address 1: \" + ip);\n  gs.info(\"ip address 2: \" + start_ip);\n  gs.info(\"ip address 1 is v6?: \" + SNC.IPAddress.isV6(ip));\n  gs.info((\"ip address 2 is v6?: \" + SNC.IPAddress.isV6(start_ip));\n}\n```\n\nOutput:\n\n```\nip address 1: 192.168.0.1\nip address 2: ::2\nip address 1 is v6?: false\nip address 2 is v6?: true\n```\n\nThe following example shows how to use the scoped non-static version of this method to verify whether IP addresses in a record in the Discovery IP Ranges \\[discovery\\_range\\_item\\] table are valid IPv6 addresses.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('discovery_range_item');\n  grDiscover.get(\"SYS_ID\");\n\n  var ip = grDiscover.getValue('network_ip');\n  var start_ip = grDiscover.getValue('start_ip_address');\n  gs.info(\"ip address 1: \" + ip);\n  gs.info(\"ip address 2: \" + start_ip);\n\n  gs.info(\"ip address 1 is v6?: \" + new SNC.IPAddress(ip).isV6());\n  gs.info(\"ip address 2 is v6?: \" + new SNC.IPAddress(start_ip).isV6());\n\n}\n```\n\nOutput:\n\n```\nip address 1: 192.168.0.1\nip address 2: ::1\nip address 1 is v6?: false\nip address 2 is v6?: true\n```\n\n## IPAddress - isValid\\(String ipAddress\\)\n\nDetermines whether the specified IP address is a valid IPv4 or IPv6 address.\n\n**Note:** This is a static method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|ipAddress|String|IP address to validate.|\n\n<table id=\"table_pnf_mcn_htb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the specified IP address is a valid IPv4 or IPv6 address.\n\n Valid values:\n\n-   true: IP address is valid.\n-   false: IP address is invalid.\n\n</td></tr></tbody>\n</table>The following code example shows how to use the scoped version of this method to check if the IP address in a record within the Configuration Items \\[cmdb\\_ci\\] is valid.\n\n```\nfunction() {\n  var grCMDB = new GlideRecord('cmdb_ci');\n  grCMDB.get(\"SYS_ID\");\n  var ip = grCMDB.getValue('ip_address');\n  gs.info(\"ip address: \" + ip)\n  var ipAddress = new SNC.IPAddress(ip);\n  gs.info(\"ip is valid?: \" + ipAddress.isValid())\n}\n```\n\nOutput:\n\n```\nip address: 127.0.0.1\nip is valid?: true\n```\n\n## IPAddress - toExpanded\\(\\)\n\nReturns the expanded form of an IPAddress object.\n\n**Note:** This is a non-static method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Expanded IP address.|\n\nThe following example shows how to use the scoped version of this method to expand an IPv6 IP address.\n\n```\nfunction() {\n  var grDiscover = new GlideRecord('cmdb_ci');\n  grDiscover.get(\"SYS_ID\");\n  var ip = grDiscover.getValue('ip_address');\n  gs.info(\"ip address: \" + ip);\n  gs.info(\"expanded ip address: \" + new SNC.IPAddress(ip).toExpanded());\n}\n```\n\nOutput:\n\n```\nip address: 2001:41::1\nexpanded ip address: 2001:0041:0000:0000:0000:0000:0000:0001\n```\n\n"}}