parse_ipv6()parse_ipv6()

将 IPv6 或 IPv4 字符串转换为规范 IPv6 字符串表示形式。Converts IPv6 or IPv4 string to a canonical IPv6 string representation.

parse_ipv6("127.0.0.1") == '0000:0000:0000:0000:0000:ffff:7f00:0001'
parse_ipv6(":fe80::85d:e82c:9446:7994") == 'fe80:0000:0000:0000:085d:e82c:9446:7994'

语法Syntax

parse_ipv6(Expr)

参数Arguments

  • Expr :表示将转换为规范 IPv6 表示形式的 IPv6/IPv4 网络地址的字符串表达式。Expr: String expression representing IPv6/IPv4 network address that will be converted to canonical IPv6 representation. 字符串可以包含使用 IP 前缀表示法的网络掩码。String may include net-mask using IP-prefix notation.

IP 前缀表示法IP-prefix notation

IP 地址可通过使用左斜线 (/) 字符的 IP-prefix notation 进行定义。IP addresses can be defined with IP-prefix notation using a slash (/) character. 左斜线 (/) 左边的 IP 地址是基本 IP 地址。The IP address to the LEFT of the slash (/) is the base IP address. 左斜线 (/) 右边的数字(1 到 127)是网络掩码中连续 1 位的数目。The number (1 to 127) to the RIGHT of the slash (/) is the number of contiguous 1 bits in the netmask.

返回Returns

如果转换成功,则结果将是表示规范 IPv6 网络地址的字符串。If conversion is successful, the result will be a string representing a canonical IPv6 network address. 如果转换未成功,结果将为 nullIf conversion isn't successful, the result will be null.

示例Example

datatable(ip_string:string, netmask:long)
[
 '192.168.255.255',     32,  // 32-bit netmask is used
 '192.168.255.255/24',  30,  // 24-bit netmask is used, as IPv4 address doesn't use upper 8 bits
 '255.255.255.255',     24,  // 24-bit netmask is used
]
| extend ip_long = parse_ipv4_mask(ip_string, netmask)
ip_stringip_string 网络掩码netmask ip_longip_long
192.168.255.255192.168.255.255 3232 32323010553232301055
192.168.255.255/24192.168.255.255/24 3030 32323008003232300800
255.255.255.255255.255.255.255 2424 42949670404294967040