parse_ipv6_mask()parse_ipv6_mask()
将 IPv6/IPv4 字符串和网络掩码转换为规范的 IPv6 字符串表示形式。Converts IPv6/IPv4 string and netmask to a canonical IPv6 string representation.
parse_ipv6_mask("127.0.0.1", 24) == '0000:0000:0000:0000:0000:ffff:7f00:0000'
parse_ipv6_mask(":fe80::85d:e82c:9446:7994", 120) == 'fe80:0000:0000:0000:085d:e82c:9446:7900'
语法Syntax
parse_ipv6_mask(
Expr
,
PrefixMask
)
参数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.PrefixMask
:从 0 到 128 的整数,表示所考虑的最高有效位数。PrefixMask
: An integer from 0 to 128 representing the number of most-significant bits that are taken into account.
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 bit in the netmask.
返回Returns
如果转换成功,则结果将是表示规范 IPv6 网络地址的字符串。If conversion is successful, the result will be a string representing a canonical IPv6 network address.
如果转换未成功,结果将为 null
。If conversion isn't successful, the result will be null
.
示例Example
datatable(ip_string:string, netmask:long)
[
// IPv4 addresses
'192.168.255.255', 120, // 120-bit netmask is used
'192.168.255.255/24', 124, // 120-bit netmask is used, as IPv4 address doesn't use upper 8 bits
'255.255.255.255', 128, // 128-bit netmask is used
// IPv6 addresses
'fe80::85d:e82c:9446:7994', 128, // 128-bit netmask is used
'fe80::85d:e82c:9446:7994/120', 124, // 120-bit netmask is used
// IPv6 with IPv4 notation
'::192.168.255.255', 128, // 128-bit netmask is used
'::192.168.255.255/24', 128, // 120-bit netmask is used, as IPv4 address doesn't use upper 8 bits
]
| extend ip6_canonical = parse_ipv6_mask(ip_string, netmask)
ip_stringip_string | 网络掩码netmask | ip6_canonicalip6_canonical |
---|---|---|
192.168.255.255192.168.255.255 | 120120 | 0000:0000:0000:0000:0000:ffff:c0a8:ff000000:0000:0000:0000:0000:ffff:c0a8:ff00 |
192.168.255.255/24192.168.255.255/24 | 124124 | 0000:0000:0000:0000:0000:ffff:c0a8:ff000000:0000:0000:0000:0000:ffff:c0a8:ff00 |
255.255.255.255255.255.255.255 | 128128 | 0000:0000:0000:0000:0000:ffff:ffff:ffff0000:0000:0000:0000:0000:ffff:ffff:ffff |
fe80::85d:e82c:9446:7994fe80::85d:e82c:9446:7994 | 128128 | fe80:0000:0000:0000:085d:e82c:9446:7994fe80:0000:0000:0000:085d:e82c:9446:7994 |
fe80::85d:e82c:9446:7994/120fe80::85d:e82c:9446:7994/120 | 124124 | fe80:0000:0000:0000:085d:e82c:9446:7900fe80:0000:0000:0000:085d:e82c:9446:7900 |
::192.168.255.255::192.168.255.255 | 128128 | 0000:0000:0000:0000:0000:ffff:c0a8:ffff0000:0000:0000:0000:0000:ffff:c0a8:ffff |
::192.168.255.255/24::192.168.255.255/24 | 128128 | 0000:0000:0000:0000:0000:ffff:c0a8:ff000000:0000:0000:0000:0000:ffff:c0a8:ff00 |