Source from here
Question
So how can I get the IP address of specific network interface in Python?
HowTo
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. Before all, let's check out network interfaces:
Then check below code snippet for how to retrieve IP address:
Method #2 (no external package)
Here's a way to get the IP address without using a python package:
So how can I get the IP address of specific network interface in Python?
HowTo
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. Before all, let's check out network interfaces:
Then check below code snippet for how to retrieve IP address:
Method #2 (no external package)
Here's a way to get the IP address without using a python package: