Find interface associated with default route?

Fredrik Lundh fredrik at pythonware.com
Sun Nov 12 06:22:28 EST 2006


Neal Becker wrote:

> Any thoughts on howto find the interface associated with the default route
> (this is on linux)?

are you sure you sent this to the right newsgroup ?

is this what you want ?

 >>> import os
 >>> for line in os.popen("/sbin/route"):
...     line = line.split()
...     if line[0] == "default":
...             print line[-1]
...
eth0

</F>




More information about the Python-list mailing list