vinegar.transform.ipv4_address
Transformations for IPv4 addresses.
- vinegar.transform.ipv4_address.broadcast_address(value: str, raise_error_if_malformed: bool = False) str
Calculate the broadcast address for an IPv4 address and subnet mask.
The subnet mask must be given as part of the input string (separated from the IP address by a forward slash) and is not included in the returned broadcast address.
For example, an input of “192.168.0.1/24” results in “192.168.0.255”.
- Parameters:
value – input IP address and mask to be transformed.
raise_error_if_malformed –
Trueif a malformed IP address or mask should result in aValueErrorbeing raised,Falseif it should result in the input value being returned as is. The default isFalse.
- Returns:
broadcast address for the specified IP address and mask.
- vinegar.transform.ipv4_address.net_address(value: str, raise_error_if_malformed: bool = False) str
Calculate the network address for an IPv4 address and subnet mask.
The subnet mask must be given as part of the input string (separated from the IP address by a forward slash) and is included in the returned net address.
For example, an input of “192.168.0.1/24” results in “192.168.0.0/24”.
- Parameters:
value – input IP address and mask to be transformed.
raise_error_if_malformed –
Trueif a malformed IP address or mask should result in aValueErrorbeing raised,Falseif it should result in the input value being returned as is. The default isFalse.
- Returns:
network address for the specified IP address and mask.
- vinegar.transform.ipv4_address.normalize(value: str, raise_error_if_malformed: bool = False) str
Normalize an IPv4 address.
This function takes an IPv4 address (as a
str) and transforms it into a normalized form. This means that each byte of the IP address is represented without leading zeros. If a mask is specified (separated from the IP address by a forward slash), it is also transformed to not include any leading zeros.When a malformed IP address is encountered, the behavior depends on the
raise_error_if_malformedoption. If that option is set toTrue, aValueErroris raised. If it isFalse(the default), the input value is returned unchanged.- Parameters:
value – input IP address to be transformed.
raise_error_if_malformed –
Trueif a malformed IP address should result in aValueErrorbeing raised,Falseif it should result in the input value being returned as is. The default isFalse.
- Returns:
normalized form of the input IP address.
- vinegar.transform.ipv4_address.strip_mask(value: str, raise_error_if_malformed: bool = False) str
Strip a subnet mask from an IPv4 address (if present).
For example, for the input string “192.168.0.1/24”, this returns “192.168.0.1”. If the input IP address does not specify a subnet mask, it is returned as is.
- Parameters:
value – input IP address to be transformed.
raise_error_if_malformed –
Trueif a malformed IP address should result in aValueErrorbeing raised,Falseif it should result in the input value being returned as is. The default isFalse.
- Returns:
input IP address with the subnet mask removed.