Site Tools


ip_script

This is an old revision of the document!


Determine external IP for all MultiWAN interfaces and log to file

This script will discover the WAN IP of all WAN interfaces in a MultiWAN configuration and log them in the file /tmp/WAN-IPs.

#!/bin/sh
WAN="$(nvram get wan_ifname)"
WAN2="$(nvram get wan2_ifname)"
WAN3="$(nvram get wan3_ifname)"
WAN4="$(nvram get wan4_ifname)"

if [ "$WAN" != "" ]
  then
   if [ "$(ifconfig $WAN | grep -q UP; echo $?)" == "0" ]
    then
      echo "WAN IP address: $(curl -s --interface $WAN http://ipinfo.io/ip)"> /tmp/WAN-IPs
    else
      echo "WAN IP address: DOWN"> /tmp/WAN-IPs
   fi
fi

if [ "$WAN2" != "" ]
  then
   if [ "$(ifconfig $WAN2 | grep -q UP; echo $?)" == "0" ]
    then
      echo "WAN2 IP address: $(curl -s --interface $WAN2 http://ipinfo.io/ip)">> /tmp/WAN-IPs
    else
      echo "WAN2 IP address: DOWN">> /tmp/WAN-IPs
   fi
fi

if [ "$WAN3" != "" ]
  then
   if [ "$(ifconfig $WAN3 | grep -q UP; echo $?)" == "0" ]
    then
      echo "WAN3 IP address: $(curl -s --interface $WAN3 http://ipinfo.io/ip)">> /tmp/WAN-IPs
    else
      echo "WAN3 IP address: DOWN">> /tmp/WAN-IPs
   fi
fi

if [ "$WAN4" != "" ]
  then
   if [ "$(ifconfig $WAN4 | grep -q UP; echo $?)" == "0" ]
    then
      echo "WAN4 IP address: $(curl -s --interface $WAN4 http://ipinfo.io/ip)">> /tmp/WAN-IPs
    else
      echo "WAN4 IP address: DOWN">> /tmp/WAN-IPs
   fi
fi

ip_script.1631547821.txt.gz · Last modified: 2021/09/13 16:43 by hogwild