>       But is there any better ways to work it out ?

you could get the ip of the interface that the default route is
going through:

    route -n get default | grep 'if address' | sed 's/.*: //'

or ask ifconfig what is in the egress group and assume the first ip
on the first interface will be ok:

    ifconfig egress | grep 'inet ' | head -n1 | awk '{ print $2 }'

Reply via email to