How can I get the IP address from a NIC (network interface controller) in Python?

Two methods: Method #1 (use external package) You need to ask for the IP address that is bound to your eth0 interface. This is available from the netifaces package import netifaces as ni ip = ni.ifaddresses(‘eth0’)[ni.AF_INET][0][‘addr’] print(ip) # should print “192.168.100.37” You can also get a list of all available interfaces via ni.interfaces() Method #2 … Read more