Best way to get wan ip on cli/ash script?

If your problem doesn't fall into one of the other categories, report it here.

Moderator: Moderators

Post Reply
agrohe21
Posts: 95
Joined: Wed Aug 23, 2017 7:51 pm

Best way to get wan ip on cli/ash script?

Post by agrohe21 »

I dont see a uci setting or a script for this.

I am currently getting this was. Is it correct? Is there another/better way?

Code: Select all

ip addr list eth1.2|grep inet|awk '{print $2}'|sed 's/\/22//'
Linksys WRT32x Wired Gateway, Orbi RBK20 Wifi
Linksys WRT32x Wired Gateway, Orbi RBK50 Wifi

agrohe21
Posts: 95
Joined: Wed Aug 23, 2017 7:51 pm

Re: Best way to get wan ip on cli/ash script?

Post by agrohe21 »

I do see an entry in /var/state/network

that is probably better/safer, right?
network.wan.ipaddr
Linksys WRT32x Wired Gateway, Orbi RBK20 Wifi
Linksys WRT32x Wired Gateway, Orbi RBK50 Wifi

Lantis
Moderator
Posts: 6753
Joined: Mon Jan 05, 2015 5:33 am
Location: Australia

Re: Best way to get wan ip on cli/ash script?

Post by Lantis »

Network state is ok.
Is this for use in a script? If so, I would import the network functions file and use it.

Code: Select all

source /lib/functions/network.sh
network_find_wan NET_IF
network_get_ipaddr NET_ADDR "${NET_IF}"
echo "${NET_ADDR}"
http://lantisproject.com/downloads/gargoyle_ispyisail.php for the latest releases
Please be respectful when posting. I do this in my free time on a volunteer basis.

agrohe21
Posts: 95
Joined: Wed Aug 23, 2017 7:51 pm

Re: Best way to get wan ip on cli/ash script?

Post by agrohe21 »

Yes, it is for a script. thx for the tip
Linksys WRT32x Wired Gateway, Orbi RBK20 Wifi
Linksys WRT32x Wired Gateway, Orbi RBK50 Wifi

Post Reply