In my Python script, I need to get both the IP address of the computer on which the script is running, and its network address and its network bytes.
Regarding the IP address, I found a solution in the archive:
import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("www.google.com",80)) myAddress = (s.getsockname()[0]) s.close()
But how do I find the network address and network bytes? I need to put this information in a filter for tcpdump in the format $NetworkAddress/$NetworkBytes
, if that helps at all.
Example:
128.1.2.0/20
I can find it under inet
when I run ip addr
. Any easy way to get this info in Python?
source share