What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

wan-event and wan0_realip_ip

Mikii

Regular Contributor
Hi,

if wan-event $2 is set to “connected”,

Do you think I can assume that wan0_realip_ip is set to the external IP, and that I can safely execute a curl
Or
should I still perform a double check on wan0_realip_ip and curl connectivity before using them?
 
I do something like this to make sure the connected event is for the public ISP address, versus no address or the cable modem temporary address while the modem initializes. You could check similarly for realip if you know what it shouldn’t be (empty or private).
Code:
# cat wan-event
#!/bin/sh

WANUNIT="$1"
WANIP="$(nvram get wan${WANUNIT}_ipaddr)"
STATE="$2"

if [ "$STATE" = "connected" ] && [ ! -f /tmp/adblock/blocklist.gz ]; then
        case $WANIP in
                0.0.0.0|192.168.100.*) ;;
                *) /jffs/addons/adblock/adblock.sh update & ;;
        esac
fi
I have another script that waits for the internet connected status before downloading an Adblock list.

Code:
        local tries
        tries=0
        until [ "$(nvram get link_internet)" = "2" ] || [ "${tries}" -ge "6" ]; do
                logmsg "Waiting for internet connection..."
                sleep 5
                tries=$(( tries + 1 ))
        done
        [ "${tries}" -eq "0" ] || logmsg "Internet connected!"
 
Thanks @dave14305 for your suggestions.

If I understand it correctly you are checking two different variables to assess if "internet is up":

wan${WANUNIT}_ipaddr and link_internet.

I'll use a similar approach to be on the safe side.

I appreciate your suggestions.
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top