Updated on 2025-08-14 GMT+08:00

IP Address Functions

This section describes IP address functions, including their syntax, parameters, and usage examples.

Function List

Table 1 IP address functions

Function

Description

ip_to_domain

Checks whether the target IPv4 address is internal or external.

ip_prefix

Obtains the prefix of the target IPv4 address.

is_prefix_subnet_of

Checks whether the target IPv4 CIDR block is a subnet of a specified CIDR block.

is_subnet_of

Checks whether the target IPv4 address is in a specified CIDR block.

ip_subnet_max

Obtains the largest IP address in an IPv4 CIDR block.

ip_subnet_min

Obtains the smallest IP address in an IPv4 CIDR block.

ip_subnet_range

Obtains the range of an IPv4 CIDR block.

ip_to_city

Returns the name of the city where an IPv4 address is located.

ip_to_provider

Returns the carrier name of an IPv4 address.

ipv6_to_country

Returns the carrier name of an IPv6 address.

ipv6_to_country_code

Returns the code of the country where an IPv6 address is located.

ipv6_to_province

Returns the name of the province where an IPv6 address is located.

ipv6_to_city

Returns the name of the city where an IPv6 address is located.

ipv6_to_provider

Returns the network service provider of an IPv6 address.

ipv6_to_city_geo

Returns the coordinates of the city where an IPv6 address is located.

ipv6_to_geo

Returns the coordinates of the city where an IPv6 address is located.

ipv6_to_domain

Checks whether the IP address is an intranet address.

ip_to_domain

This function checks whether the target IPv4 address is internal or external.

Syntax: ip_to_domain(expr)

Table 2 Parameter description

Parameter

Description

Type

Mandatory

expr

IP address.

String

Yes

Return value type: string

Example: SELECT IP_TO_DOMAIN('10.110.10.210'), IP_TO_DOMAIN('192.175.4.1')

Table 3 Query and analysis results

Type

Query Statement

Returned Result

Scenario 1

IP_TO_DOMAIN('10.110.10.210')

intranet

Scenario 2

IP_TO_DOMAIN('192.175.4.1')

internet

ip_prefix

This field obtains the prefix of the target IPv4 address.

Syntax: ip_prefix(expr, prefixBit)

Table 4 Parameter description

Parameter

Description

Type

Mandatory

expr

IPv4 Address

String

Yes

prefixBit

Number of prefix digits.

String

Yes

Return value type: string

Example: SELECT IP_PREFIX('10.110.10.210', 8), IP_PREFIX('144.101.32.5', 12)

Table 5 Query and analysis results

Type

Query Statement

Returned Result

Scenario 1

IP_PREFIX('10.110.10.210', 8)

10.0.0.0/8

Scenario 2

IP_PREFIX('144.101.32.5', 12)

144.96.0.0/12

is_prefix_subnet_of

This function checks whether the target IPv4 CIDR block is a subnet of a specified CIDR block.

Syntax: is_prefix_subnet_of(expr1, expr2)

Table 6 Parameter description

Parameter

Description

Type

Mandatory

expr1

Specified IPv4 CIDR block.

String

Yes

expr2

Target IPv4 CIDR block.

String

Yes

Return value type: Boolean

Example: SELECT IS_PREFIX_SUBNET_OF('192.168.0.1/24', '192.168.1.1/24')

Table 7 Query and analysis results

Type

Query Statement

Returned Result

Scenario

IS_PREFIX_SUBNET_OF('192.168.0.1/24', '192.168.1.1/24')

false

is_subnet_of

This function checks whether the target IPv4 address is in a specified CIDR block.

Syntax: is_subnet_of(expr1, expr2)

Table 8 Parameter description

Parameter

Description

Type

Mandatory

expr1

Specified IPv4 CIDR block.

String

Yes

expr2

Target IPv4 address.

String

Yes

Return value type: Boolean

Example: SELECT IS_SUBNET_OF('192.168.0.1/24', '192.168.1.1')

Table 9 Query and analysis results

Type

Query Statement

Returned Result

Scenario

IS_SUBNET_OF('192.168.0.1/24', '192.168.1.1')

false

ip_subnet_max

This function obtains the largest IP address in an IPv4 CIDR block.

Syntax: ip_subnet_max(expr)

Table 10 Parameter description

Parameter

Description

Type

Mandatory

expr

IPv4 CIDR block.

String

Yes

Return value type: string

Example: SELECT IP_SUBNET_MAX('192.120.80.128/10')

Table 11 Query and analysis results

Type

Query Statement

Returned Result

Scenario

IP_SUBNET_MAX('192.120.80.128/10')

192.127.255.255

ip_subnet_min

This function obtains the smallest IP address in an IPv4 CIDR block.

Syntax: ip_subnet_min(expr)

Table 12 Parameter description

Parameter

Description

Type

Mandatory

expr1

IPv4 CIDR block.

String

Yes

Return value type: string

Example: SELECT IP_SUBNET_MIN('192.120.80.128/10')

Table 13 Query and analysis results

Type

Query Statement

Returned Result

Scenario

IP_SUBNET_MIN('192.120.80.128/10')

192.64.0.0

ip_subnet_range

This function obtains the range of an IPv4 CIDR block.

Syntax: ip_subnet_range(expr)

Table 14 Parameter description

Parameter

Description

Type

Mandatory

expr1

IPv4 CIDR block.

String

Yes

Return value type: string

Example: SELECT IP_SUBNET_RANGE('192.120.80.128/10')

Table 15 Query and analysis results

Type

Query Statement

Returned Result

Scenario

IP_SUBNET_RANGE ('192.120.80.128/10')

["192.64.0.0","192.127.255.255"]

When the maximum IP address, minimum IP address, and IP address range of a given CIDR block are calculated, its unicast and broadcast addresses are excluded. The maximum and minimum available IP addresses and the available IP address range of the CIDR block is returned.

ip_to_city

This function returns the city of an IPv4 address.

Syntax: ip_to_city(x)

Table 16 Parameter description

Parameter

Description

Type

Mandatory

x

IPv4 address.

String

Yes

Return value type: string

Example: select ip_to_city(ip)

Table 17 Query and analysis results

Type

Query Statement

Returned Result

Scenario

ip_to_city(ip)

Cochise

ip_to_provider

This function returns the carrier name of an IPv4 address.

Syntax: ip_to_provider(x)

Table 18 Parameter description

Parameter

Description

Type

Mandatory

x

IPv4 address.

String

Yes

Return value type: string

Example: select ip_to_provider(ip)

Table 19 Query and analysis results

Type

Query Statement

Returned Result

Scenario

ip_to_provider(ip)

CONUS-YPG

ipv6_to_country

This function returns the carrier name of an IPv6 address.

Syntax: ipv6_to_country(x)

Table 20 Parameter description

Parameter

Description

Type

Mandatory

x

IPv6 address.

String

Yes

Return value type: string

Example: select ipv6_to_country(ip)

Table 21 Query and analysis results

Type

Query Statement

Returned Result

Scenario

ipv6_to_country(ip)

China

ipv6_to_country_code

This function returns the code of the country where an IPv6 address is located.

Syntax: ipv6_to_country_code(x)

Table 22 Parameter description

Parameter

Description

Type

Mandatory

x

IPv6 address.

String

Yes

Return value type: string

Example: select ipv6_to_country_code(ip)

Table 23 Query and analysis results

Type

Query Statement

Returned Result

Scenario

ipv6_to_country_code(ip)

CN

ipv6_to_province

This function returns the name of the province where an IPv6 address is located.

Syntax: ipv6_to_province(x)

Table 24 Parameter description

Parameter

Description

Type

Mandatory

x

IPv6 address.

String

Yes

Return value type: string

Example: select ipv6_to_province(ip)

Table 25 Query and analysis results

Type

Query Statement

Returned Result

Scenario

ipv6_to_province(ip)

Shaanxi

ipv6_to_city

This function returns the name of the city where an IPv6 address is located.

Syntax: ipv6_to_city(x)

Table 26 Parameter description

Parameter

Description

Type

Mandatory

x

IPv6 address.

String

Yes

Return value type: string

Example: select ipv6_to_city(ip)

Table 27 Query and analysis results

Type

Query Statement

Returned Result

Scenario

ipv6_to_city(ip)

Xi'an

ipv6_to_provider

This function returns the network service provider of an IPv6 address.

Syntax: ipv6_to_provider(x)

Table 28 Parameter description

Parameter

Description

Type

Mandatory

x

IPv6 address.

String

Yes

Return value type: string

Example: select ipv6_to_provider(ip)

Table 29 Query and analysis results

Type

Query Statement

Returned Result

Scenario

ipv6_to_provider(ip)

China Telecom

ipv6_to_city_geo

This function returns the coordinates of the city where an IPv6 address is located.

Syntax: ipv6_to_city_geo(x)

Table 30 Parameter description

Parameter

Description

Type

Mandatory

x

IPv6 address.

String

Yes

Return value type: string

Example: select ipv6_to_city_geo(ip)

Table 31 Query and analysis results

Type

Query Statement

Returned Result

Scenario

ipv6_to_city_geo(ip)

39.904989,116.405285

ipv6_to_geo

This function returns the coordinates of the city where an IPv6 address is located.

Syntax: ipv6_to_geo(x)

Table 32 Parameter description

Parameter

Description

Type

Mandatory

x

IPv6 address.

String

Yes

Return value type: string

Example: select ipv6_to_geo(ip)

Table 33 Query and analysis results

Type

Query Statement

Returned Result

Scenario

ipv6_to_geo(ip)

39.904989,116.405285

ipv6_to_domain

This function checks whether the IP address is an intranet address.

Syntax: ipv6_to_domain(x)

Table 34 Parameter description

Parameter

Description

Type

Mandatory

x

IPv6 address.

String

Yes

Return value type: string

Example: select ipv6_to_domain(ip)

Table 35 Query and analysis results

Type

Query Statement

Returned Result

Scenario

ipv6_to_domain(ip)

internet