1
I’m using Linux Mint 17 and am making a Conky script. I’d like it to display the hostname of the router/access point I’m connected to. I just don’t know the Linux command to get it.
1
I’m using Linux Mint 17 and am making a Conky script. I’d like it to display the hostname of the router/access point I’m connected to. I just don’t know the Linux command to get it.
2
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
0
Hostname and ESSID
are two different things.
But if you're using Conky and want ESSID
it's something like this:
${offset 60}${font Ubuntu:size=12,weight:normal}${color1}Wlan0: ${wireless_essid wlan0}
Since it is now clear to me you actually mean the hostname of the external IP of an AP and not confusion of hostname and ESSID.
You can create a script and place it in your .conky/script
directory
mkdir ~/.conky/scripts
gedit ~/.conky/scripts/hostname.sh
#!/bin/bash
dig +short myip.opendns.com @resolver1.opendns.com | xargs dig +short -x
Make it executable chmod +x ~/conky/scripts/hostname.sh
add to your .conkyrc
something like
${offset 60}${font Ubuntu:size=12,weight:normal}${color1}Hostname: ${execi 10000 ~/.conky/scripts/hostname.sh}
Sorry, should've specified that I wanted it for a wired connection. – leetwanker – 2015-03-06T03:44:29.190
@leetwanker Thanks. Like I said, only realized you were asking about Conky specific info after I wrote the post. Hopefully this can help someone. Maybe you?
– JakeGould – 2015-03-06T03:48:57.7771
It was exactly what I was looking for. Check out a screenshot: link
– leetwanker – 2015-03-06T04:11:26.570@leetwanker Hey! It worked! Happy to have helped. – JakeGould – 2015-03-06T04:15:18.027
1
Think I'm finally done tinkering with it. Screenshot: link
– leetwanker – 2015-03-06T04:47:29.643