Site Tools


ip_script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ip_script [2020/08/20 09:21] seanbip_script [2023/05/28 05:47] (current) hogwild
Line 1: Line 1:
-This script will discover the WAN IP of each WAN interface in a MultiWAN configuration and log them in /tmp/WAN-IPs.+====== Determine external IP for all MultiWAN interfaces and log to file ======
  
----------------------------------------------------------+\\
  
-  #!/bin/sh +This script will discover the WAN IP of all WAN interfaces in a MultiWAN configuration and log them in the file: "/tmp/WAN-IPs:\\ \\ \\
-  WAN="$(nvram get wan_ifname)" +
-  WAN2="$(nvram get wan2_ifname)" +
-  WAN3="$(nvram get wan3_ifname)" +
-  WAN4="$(nvram get wan4_ifname)"+
  
 +<code ->
 +#!/bin/sh
 +WAN="$(nvram get wan_ifname)"
 +WAN2="$(nvram get wan2_ifname)"
 +WAN3="$(nvram get wan3_ifname)"
 +WAN4="$(nvram get wan4_ifname)"
  
-  if [ "$WAN" != "" ]+if [ "$WAN" != "" ] 
 +  then 
 +   if [ "$(ifconfig $WAN | grep -q UP; echo $?)" == "0" ]
     then     then
-     if [ "$(ifconfig $WAN | grep -q UP; echo $?)" == "0"+      echo "WAN IP address: $(curl -s --interface $WAN http://ipinfo.io/ip)"> /tmp/WAN-IPs 
-      then +    else 
-        echo "WAN IP address: $(curl -s --interface $WAN http://ipinfo.io/ip)" > /tmp/WAN-IPs +      echo "WAN IP address: DOWN"> /tmp/WAN-IPs 
-      else +   fi 
-        echo "WAN IP address: DOWN" > /tmp/WAN-IPs +fi
-     fi +
-  fi+
  
-  if [ "$WAN2" != "" ]+if [ "$WAN2" != "" ] 
 +  then 
 +   if [ "$(ifconfig $WAN2 | grep -q UP; echo $?)" == "0" ]
     then     then
-     if [ "$(ifconfig $WAN2 | grep -q UP; echo $?)" == "0"+      echo "WAN2 IP address: $(curl -s --interface $WAN2 http://ipinfo.io/ip)">> /tmp/WAN-IPs 
-      then +    else 
-        echo "WAN2 IP address: $(curl -s --interface $WAN2 http://ipinfo.io/ip)" >> /tmp/WAN-IPs +      echo "WAN2 IP address: DOWN">> /tmp/WAN-IPs 
-      else +   fi 
-        echo "WAN2 IP address: DOWN" >> /tmp/WAN-IPs +fi
-     fi +
-  fi+
  
-  if [ "$WAN3" != "" ]+if [ "$WAN3" != "" ] 
 +  then 
 +   if [ "$(ifconfig $WAN3 | grep -q UP; echo $?)" == "0" ]
     then     then
-     if [ "$(ifconfig $WAN3 | grep -q UP; echo $?)" == "0"+      echo "WAN3 IP address: $(curl -s --interface $WAN3 http://ipinfo.io/ip)">> /tmp/WAN-IPs 
-      then +    else 
-        echo "WAN3 IP address: $(curl -s --interface $WAN3 http://ipinfo.io/ip)" >> /tmp/WAN-IPs +      echo "WAN3 IP address: DOWN">> /tmp/WAN-IPs 
-      else +   fi 
-        echo "WAN3 IP address: DOWN" >> /tmp/WAN-IPs +fi
-     fi +
-  fi+
  
-  if [ "$WAN4" != "" ]+if [ "$WAN4" != "" ] 
 +  then 
 +   if [ "$(ifconfig $WAN4 | grep -q UP; echo $?)" == "0" ]
     then     then
-     if [ "$(ifconfig $WAN4 | grep -q UP; echo $?)" == "0"+      echo "WAN4 IP address: $(curl -s --interface $WAN4 http://ipinfo.io/ip)">> /tmp/WAN-IPs 
-      then +    else 
-        echo "WAN4 IP address: $(curl -s --interface $WAN4 http://ipinfo.io/ip)" >> /tmp/WAN-IPs +      echo "WAN4 IP address: DOWN">> /tmp/WAN-IPs 
-      else +   fi 
-        echo "WAN4 IP address: DOWN" >> /tmp/WAN-IPs +fi 
-     fi +</code> 
-  fi+ 
 + \\ 
 + 
 + \\ 
 + 
 +---- 
  
---------------------------------------------------------- 
ip_script.1597911711.txt.gz · Last modified: 2020/08/20 09:21 by seanb