Using python3, how is it possible to get the network IP address from an interface IP and netmask?
Example:
Having:
eth0 IP: 192.168.1.11 # string
netmask: 255.255.255.0 # string
I need to obtain:
network IP: 192.168.1.0 # string
You can use the Python ipaddress
module:
import ipaddress
net = ipaddress.ip_network('192.168.1.11/255.255.255.0', strict=False)
net.network_address
# IPv4Address('192.168.1.0')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.