Find interface associated with default route?
Neal Becker
ndbecker2 at gmail.com
Sun Nov 12 07:01:24 EST 2006
Fredrik Lundh wrote:
> 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
>
Well, I was hoping for something more 'elegant' - meaning relying on library
calls rather than calling programs. Obviously, /sbin/route has some
library calls to obtain this info, and maybe python has a wrapper for it.
Yes, this is the right group - I want a python solution.
More information about the Python-list
mailing list