format_ipv4_mask()format_ipv4_mask()

使用网络掩码分析输入,并以 CIDR 表示法返回表示 IPv4 地址的字符串。Parses input with a netmask and returns string representing IPv4 address as CIDR notation.

print format_ipv4_mask('192.168.1.255', 24) == '192.168.1.0/24'
print format_ipv4_mask(3232236031, 24) == '192.168.1.0/24'

语法Syntax

format_ipv4_mask(Expr [, PrefixMask])format_ipv4_mask(Expr [, PrefixMask])

参数Arguments

  • Expr :以 CIDR 表示法表示的 IPv4 地址的字符串或数字表示形式。Expr: A string or number representation of the IPv4 address as CIDR notation.
  • PrefixMask :(可选)从 0 到 32 的整数,表示所考虑的最有效位的数目。PrefixMask: (Optional) An integer from 0 to 32 representing the number of most-significant bits that are taken into account. 如果未指定参数,则使用所有位掩码 (32)。If argument isn't specified, all bit-masks are used (32).

返回Returns

如果转换成功,则结果将是以 CIDR 表示法表示 IPv4 地址的字符串。If conversion is successful, the result will be a string representing IPv4 address as CIDR notation. 如果转换不成功,则结果将为空字符串。If conversion isn't successful, the result will be an empty string.

请参阅See also

示例Examples

datatable(address:string, mask:long)
[
 '192.168.1.1', 24,          
 '192.168.1.1', 32,          
 '192.168.1.1/24', 32,       
 '192.168.1.1/24', long(-1), 
]
| extend result = format_ipv4(address, mask), 
         result_mask = format_ipv4_mask(address, mask)
addressaddress 掩码mask resultresult result_maskresult_mask
192.168.1.1192.168.1.1 2424 192.168.1.0192.168.1.0 192.168.1.0/24192.168.1.0/24
192.168.1.1192.168.1.1 3232 192.168.1.1192.168.1.1 192.168.1.1/32192.168.1.1/32
192.168.1.1/24192.168.1.1/24 3232 192.168.1.0192.168.1.0 192.168.1.0/24192.168.1.0/24
192.168.1.1/24192.168.1.1/24 -1-1