On Linux, how can I find the default gateway for a local ip address/interface using python?
I saw the question \"How to get internal IP, external IP and default gate
def get_ip():
file=os.popen("ifconfig | grep 'addr:'")
data=file.read()
file.close()
bits=data.strip().split('\n')
addresses=[]
for bit in bits:
if bit.strip().startswith("inet "):
other_bits=bit.replace(':', ' ').strip().split(' ')
for obit in other_bits:
if (obit.count('.')==3):
if not obit.startswith("127."):
addresses.append(obit)
break
return addresses