Determine IP address of CONNECTED interface (linux) in python -


on linux machine, 1 of 3 network interfaces may connected internet. need ip address of connected interface, keeping in mind other 2 interfaces may assigned ip addresses, not connected.

i can ping website through each of interfaces determine 1 has connectivity, i'd faster waiting ping time out. , i'd not have rely on external website being up.

update:

all interfaces may have ip addresses , gateways. embedded device. allow user choose between eth0 , eth1. if there's no connection on interface user tells use, fall eth2 (in theory) work.

so need first check if user's selection connected , if return ip. otherwise need ip of eth2. can ips of interfaces fine, it's determining 1 connected.

if default gateway system reliable, grab output route -n line contains " ug " (note spaces) contain ip of gateway , interface name of active interface.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -