Skip to content

Instantly share code, notes, and snippets.

@dash17291
Created August 16, 2014 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dash17291/dbae07b250f32483e9b4 to your computer and use it in GitHub Desktop.
Save dash17291/dbae07b250f32483e9b4 to your computer and use it in GitHub Desktop.
ipurl=( 'http://whatismyipaddress.com/' 'http://www.ip-adress.com/' 'http://ip.ezit.hu/ip.php' \
'http://www.whatismyip.org/' 'http://www.cmyip.com/' 'http://my-i-p.com/' \
'http://ifconfig.me/ip' 'http://freedns.afraid.org/dynamic/check.php' 'http://checkip.dyndns.org/' )
user_agent='Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20100101 Firefox/8.0'
iface='p10p1'
releasefile='/etc/system-release'
name="${0##*/}"
wanaddr() {
max=0
maxindex=0
IP[0]=0
for ((i=0; i<${#ipurl[@]}; i++)); do
url="${ipurl[i]}"
ip="`wget -l1 -U "$user_agent" -O - "$url" 2>/dev/null | grep -Eo '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}' | head -n1`"
[ -z "$ip" ] && continue
ready=0
j=0
while [ ${IP[j]} -ne 0 ]; do
if [ x"${IP[j+1]}" = x"$ip" ]; then
((IP[j]++))
if [ ${IP[j]} -gt $max ]; then
max=${IP[j]}
maxindex=$j
fi
ready=1
break
fi
((j+=2))
done
if [ $ready -ne 1 ]; then
if [ 1 -gt $max ]; then
max=1
maxindex=$j
fi
IP[j++]=1
IP[j++]="$ip"
IP[j]=0
fi
done
IPADDR="${IP[maxindex+1]}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment