Valid ip detection script

I need a script that after connecting "pppoe", detects if the ip is valid, if not disconnects "Pppoe" and reconnects after a time set in seconds.
My internet provider insists on giving me an invalid ip, and if I get reconnected, the valid ip is granted.

How about beating them to the punch with this DHCP renewal workaround?

My ISP doesn't provide IPv6, but myself trying to find a way to solve the problem of my PPOE dynamic IP, I wrote this little script based on the watchdog script. It detects if the WAN_PPPOE IP is within the range I configured, if not it restarts the WAN after a few seconds, and after 60 times it restarts the router, for me it solved, my valid IP is in the range of 179.0.0.0 . If it works for anyone else, here's the script.

#!/bin/sh

logread -l 100 | grep -n "IEEE 802.11: did not acknowledge authentication response"
if [ $? -eq 0 ]; then
	/etc/init.d/network restart
fi
. /lib/functions/network.sh

echo "Valid Ip Detect"
sleep 20
n=0

export IFS="."
function convertToNumber() {
	ipNumber=""
	for i in $1; do
		part="$i"
		while [ ${#part} -lt 3 ]; do
			part="0${part}"
		done
		ipNumber="${ipNumber}${part}"
	done
	echo ${ipNumber}
}

min=$(convertToNumber "140.0.0.0")
max=$(convertToNumber "180.0.0.0")

while [ 1 ]; do

	network_flush_cache
	network_find_wan NET_IF
	network_get_ipaddr NET_ADDR "${NET_IF}"
	#network_get_gateway NET_GW "${NET_IF}"
	realip="${NET_ADDR}"
	ip=$(convertToNumber "${NET_ADDR}")
	#GATEWAY="${NET_GW}"
	#echo "$GATEWAY"

	if [ $ip -ge $min ] && [ $ip -le $max ]; then
		echo "Success - Valid IP - $realip"
		exit 0
	else
		echo "Fail - No Valid IP - $realip"
		n=$((n+1))
		ifdown wan
		echo "Wan down!"
		sleep 10
		echo "Wan up!"
		ifup wan
		sleep 10
	fi

	echo fail counter $n
	if [ $n -gt 60 ]; then
		reboot
	fi
done

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.