Programmatic way to find interface

Ben Stringer ben at burbong.com
Sun Nov 12 11:25:56 UTC 2006


On Sun, 2006-11-12 at 06:09 -0500, Neal Becker wrote:
> What is a programmatic way to find out what interface is associated with the
> default route?
> 
> I know this could be done by parsing /proc/sys/net/route, but is there a
> more elegant solution?
> 

Not so elegant, but....

netstat -r | grep "^default" | awk ' { print $8 } '

Cheers, Ben




More information about the users mailing list