#!/bin/bash get_fg_ip_pub(){ #v adapté 11/12/2017 local dig_test ip_test list_ip4(){ # testé 12/2017 ip_test=( # pas de https http://whatismyip.akamai.com http://eth0.me ipinfo.io/ip # http & https http://alma.ch/myip.cgi # peu fiable curl http://checkip.amazonaws.com # peu fiable wget api.infoip.io/ip # http & https fiable wget api.ipify.org # http & https fiable wget http://ipecho.net/plain # peu fiable wget / curl # http://ipof.in/txt # fail wget ) } list_ip4_dig(){ # testé 12/2017 dig_test=( whoami.akamai.net/@ns1-1.akamaitech.net myip.opendns.com/@resolver1.opendns.com myip.opendns.com/@resolver2.opendns.com myip.opendns.com/@resolver3.opendns.com myip.opendns.com/@resolver4.opendns.com ) } list_ip6(){ # testé 12/2017 ip_test=( http://ipv6.whatismyip.akamai.com ip.tyk.nu # http & https wgetip.com # http & https l2.io/ip # http & https peu fiable wget icanhazip.com # http & https peu fiable wget http://bot.whatismyipaddress.com # peu fiable wget https://canhazip.com # peu fiable wget https://tnx.nl/ip # peu fiable wget ident.me # http & https peu fiable curl ) } list_ip6_dig(){ # testé 12/2017 dig_test=( -6/myip.opendns.com/aaaa/@resolver1.ipv6-sandbox.opendns.com -6/myip.opendns.com/aaaa/@resolver2.ipv6-sandbox.opendns.com ) } option="$1" unset fg_ip_pub # assignation variables if [ "$1" == "-4" ]; then ping -4 -c1 conncheck.opensuse.org &>/dev/null || ping -4 -c1 free.fr &>/dev/null || return 1 # test connectivité list_ip4_dig list_ip4 ip_telnet=4.ifcfg.me elif [ "$1" == "-6" ]; then ping -6 -c1 conncheck.opensuse.org &>/dev/null || ping -6 -c1 free.fr &>/dev/null || return 1 # test connectivité list_ip6_dig list_ip6 ip_telnet=6.ifcfg.me fi unset fg_ip_pub # DIG if type -p dig &>/dev/null && [ -z "$fg_ip_pub" ]; then for iip in ${dig_test[*]}; do fg_ip_pub=$( dig +short ${iip//\// } ) echo -e "dig $option $iip \t ${fg_ip_pub:=FAIL}" # [ "$fg_ip_pub" ] && break done fi unset fg_ip_pub # WGET if type -p wget &>/dev/null && [ -z "$fg_ip_pub" ]; then cmd="wget --quiet --timeout=2 --tries=1 -O - " for iip in ${ip_test[*]}; do fg_ip_pub=$( $cmd $iip ) echo -e "wget $option $iip\t${fg_ip_pub:=FAIL}" # [ "$fg_ip_pub" ] && break done fi unset fg_ip_pub # CURL if type -p curl &>/dev/null && [ -z "$fg_ip_pub" ]; then cmd="curl --silent --location --retry 0 --max-time 5" for iip in ${ip_test[*]}; do fg_ip_pub=$( $cmd $iip ) echo -e "curl $option $iip \t ${fg_ip_pub:=FAIL}" # [ "$fg_ip_pub" ] && break done fi unset fg_ip_pub # TELNET if type -p telnet &>/dev/null && [ -z "$fg_ip_pub" ]; then fg_ip_pub=$( telnet $ip_telnet 23 2>/dev/null | grep "Your IPv${option/-}" ) fg_ip_pub=${fg_ip_pub##* } echo -e "telnet $option $ip_telnet \t ${fg_ip_pub:=FAIL}" fi unset fg_ip_pub # NC if type -p nc &>/dev/null && [ -z "$fg_ip_pub" ] && [ "$option" != "-6" ]; then fg_ip_pub=$( nc $ip_telnet 23 2>/dev/null | grep "Your IPv${option/-}" ) fg_ip_pub=${fg_ip_pub##* } echo -e "nc $option $ip_telnet \t ${fg_ip_pub:=FAIL}" fi } get_fg_ip_pub "-4" get_fg_ip_pub "-6"