format_ipv4()format_ipv4()
使用网络掩码分析输入,并返回表示 IPv4 地址的字符串。Parses input with a netmask and returns string representing IPv4 address.
print format_ipv4('192.168.1.255', 24) == '192.168.1.0'
print format_ipv4(3232236031, 24) == '192.168.1.0'
语法Syntax
format_ipv4(
Expr [,
PrefixMask])
format_ipv4(
Expr [,
PrefixMask])
参数Arguments
Expr
:IPv4 地址的字符串或数字表示形式。Expr
: A string or number representation of the IPv4 address.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
如果转换成功,则结果将是一个表示 IPv4 地址的字符串。If conversion is successful, the result will be a string representing IPv4 address. 如果转换不成功,则结果将为空字符串。If conversion isn't successful, the result will be an empty string.
请参阅See also
- format_ipv4_mask():适用于以 CIDR 表示法设置格式的 IPv4 地址。format_ipv4_mask(): For IPv4 address formatting including CIDR notation.
- IPv4 和 IPv6 函数IPv4 and IPv6 functions
示例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 |