EDIT: Just realized the request was about a Conky specific script after posting this Bash-based answer. Leaving it up here just in case it’s useful.
Hostname for a router? Pretty sure that is not possible because most gateways don’t have a hostname assigned or even give out their hostname. But you can get the IP address using route
piped through grep
and awk
like this:
route | grep "default" | awk '{ print $2 }'
That will cleanly give you the raw IP address of the router. Now if you wanted the MAC address just do this using arp
and that command mixed in with grep
and awk
in there as well again:
arp -a | grep $(route | grep "default" | awk '{ print $2 }') | awk '{ print $4 }'
And if you wanted to assign those values to Bash variables, just do this for the router IP address:
ROUTER_IP=$(route | grep "default" | awk '{ print $2 }')
And do this for the MAC address:
ROUTER_MAC=$(arp -a | grep $(route | grep "default" | awk '{ print $2 }') | awk '{ print $4 }')
And then you could use those assigned values by referring to $ROUTER_IP
and $ROUTER_MAC
. Like if you ran those two variable assignments just now just run these echo
commands from the command line like this:
echo $ROUTER_IP echo $ROUTER_MAC