Как получить имя хоста маршрутизатора / точки доступа, к которой я подключен?

1136
leetwanker

Я использую Linux Mint 17 и делаю сценарий Conky . Я хотел бы, чтобы он отображал имя хоста маршрутизатора / точки доступа, к которой я подключен. Я просто не знаю команду Linux, чтобы получить ее.

1

2 ответа на вопрос

2
JakeGould

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 
@leetwanker Спасибо. Как я уже сказал, только понял, что вы спрашивали о [Conky] (http://conky.sourceforge.net/) конкретной информации после того, как я написал сообщение. Надеюсь, это может кому-то помочь. Может быть ты? JakeGould 9 лет назад 0
Это было именно то, что я искал. Проверьте скриншот: [ссылка] (https://leetwanker.files.wordpress.com/2015/02/screenshot-from-2015-03-05-230428.png) leetwanker 9 лет назад 1
@leetwanker Привет! Это сработало! Рад, что помог. JakeGould 9 лет назад 0
Думаю, я наконец-то покончил с этим. Снимок экрана: [ссылка] (https://leetwanker.files.wordpress.com/2015/03/screenshot-from-2015-03-05-234407.png?w=614) leetwanker 9 лет назад 1
0
Nodak

Hostname and ESSID are two different things.

But if you're using Conky and want ESSID it's something like this:

$$$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

$$$Hostname: $ 
Извините, должен был указать, что я хотел это для проводного соединения. leetwanker 9 лет назад 0