tencent cloud

Cloud Log Service

IP Parsing Functions

Download
フォーカスモード
フォントサイズ
最終更新日: 2026-05-20 19:57:55

Function geo_parse

Function Definition

This function is used to parse the geographical location.

Syntax Description

geo_parse(field value, keep=("country","province","city"), ip_sep=",")

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
IP value. Separate multiple IPs by separator.
String
Yes
-
-
keep
The field to be reserved
String
No
("country","province","city")
geo only supports returning the latitude and longitude of cities in the Chinese mainland.
-
ip_sep
The number of the expression in the match result
String
No
-
-

Example

Example 1
Raw logs:
{
{"ip":"101.132.57.150"}
}
Processing rules:
fields_set("result", geo_parse(v("ip")))
Processing result:
{
{"ip":"101.132.57.150","result":"{\\"country\\":\\"China\\",\\"province\\":\\"Shanghai\\",\\"city\\":\\"Shanghai\\"}"}
"result": {"country": "China", "province": "Guangdong", "city": "Dongguan", "provider": "China Mobile", "latitude": "23.027", "longitude": "113.758"}
}
Example 2
Raw logs:
{"ip":"101.132.57.150,101.14.57.157"}
Processing rules:
fields_set("result", geo_parse(v("ip"),keep="province,city",ip_sep=","))
Processing result:
{"ip":"101.132.57.150,101.14.57.157", "result":"{\\"101.14.57.157\\":{\\"province\\":\\"Taiwan\\",\\"city\\":\\"NULL\\"},\\"101.132.57.150\\":{\\"province\\":\\"Shanghai\\",\\"city\\":\\"Shanghai\\"}}"}

Function is_subnet_of

Function Definition

This function is used to check whether an IP is in the target IP range. Multiple IP ranges are supported.

Syntax Description

is_subnet_of(IP range list, IP)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
IP range list
IP range. Separate multiple IP ranges by comma.
String
Yes
-
-
IP
The IP to be checked
String
Yes
-
-

Example

Example 1
Raw logs:
{"ip": "192.168.1.127"}
Processing rules:
log_keep(is_subnet_of("192.168.1.64/26",v("ip")))
Processing result:
{"ip": "192.168.1.127"}
Example 2
Raw logs:
{"ip": "192.168.1.127"}
Processing rules:
fields_set("is_subnet",is_subnet_of("192.168.1.64/26",v("ip")))
Processing result:
{"ip": "192.168.1.127", "is_subnet":"true"}
Example 3
Raw logs:
{"ip": "192.168.1.127"}
Processing rule:
fields_set("is_subnet",is_subnet_of("172.16.0.0/16",v("ip")))
Processing result:
{"ip": "192.168.1.127", "is_subnet":"false"}
Example 4
Raw logs:
{"ip": "192.168.1.127"}
Processing rules:
fields_set("is_subnet",is_subnet_of("172.16.0.0/16,192.168.1.64/26",v("ip")))
Processing result:
{"ip": "192.168.1.127", "is_subnet":"true"}

inet_aton Function

Function Definition

Convert an IPv4 address from string format to unsigned integer format.

Syntax Description

inet_aton(IP)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
IP
The IP address to be converted
String
Yes
-
-

Example

Raw log:
{"ip": "192.168.0.1"}
Processing rules:
fields_set("ip_int", inet_aton(v("ip")))
Processing result:
{"ip_int":"3232235521","ip":"192.168.0.1"}

inet_ntoa Function

Function Definition

Convert an IPv4 address from unsigned integer format back to string format.

Syntax Description

inet_ntoa(number)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
number
The integer to be converted to an IP address
int
Yes
-
-

Example

Raw logs:
{"ip_int":"3232235521"}
Processing rules:
fields_set("ip", inet_ntoa(v("ip_int")))
Processing result:
{"ip_int":"3232235521","ip":"192.168.0.1"}



ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック