Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # https://en.wikipedia.org/wiki/IPv6_address
- NET_iface="`ip route | grep -n default | sort -b -k 9 | awk 'NR==1 {print $5}'`"
- if [ -z $NET_iface ]; then
- echo " Non c'è connessione di rete locale ...??"
- exit 1
- else
- PING_to="gnu.org"
- # PING_to="freegeoip.net"
- # PING_to="ae-1-3101.edge3.Dusseldorf1.Level3.net"
- # nc -zv freegeoip.net 80
- # echo -e "GET /xml/ipv6.google.com HTTP/1.0\r\n\r\n" | nc -i1 freegeoip.net 80
- ping -c 1 $PING_to 2>/dev/null 1>/dev/null
- PING_EXIT=$?
- if [ $PING_EXIT -gt 0 ]; then
- echo " \"ping -c 1 $PING_to\" exit $PING_EXIT"
- echo " Non c'è connettivita su Internet"
- exit $PING_EXIT
- fi
- fi
- # from a terminal try this
- # echo "this is not ip4 999.999.999.999" | grep -Eo "([0-9]{1,3}.){3}[[0-9]{1,3}" ; echo grep error $?
- # echo "this is ip4 1.1.1.1" | grep -Eo "([0-9]{1,3}.){3}[[0-9]{1,3}" ; echo grep error $?
- # echo "this is not ip4 999.999.999.999" | grep -Eo "`rgxg cidr 0.0.0.0/0`|`rgxg cidr ::/0`" ; echo grep error $?
- # echo "this is ip4 1.1.1.1/16 this is ip6 fe80::7627:eaff:fe21:37e ip6 ::/64 no ip4 256.1.1.256" | grep -Eo "`rgxg cidr 0.0.0.0/0`|`rgxg cidr ::/0`" ; echo grep error $?
- # ifconfig | grep -Eo "`rgxg cidr 0.0.0.0/0`|`rgxg cidr ::/0`"
- RGXG="`which rgxg`"
- if [ -z $RGXG ]; then
- # this is the output of "rgxg cidr 0.0.0.0/0", all ip4 address
- REGEX_ALL_ip4="(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}"
- # this is the output of "rgxg cidr ::/0", all ip6 address
- REGEX_ALL_ip6="((:(:[0-9A-Fa-f]{1,4}){1,7}|::|[0-9A-Fa-f]{1,4}(:(:[0-9A-Fa-f]{1,4}){1,6}|::|:[0-9A-Fa-f]{1,4}(:(:[0-9A-Fa-f]{1,4}){1,5}|::|:[0-9A-Fa-f]{1,4}(:(:[0-9A-Fa-f]{1,4}){1,4}|::|:[0-9A-Fa-f]{1,4}(:(:[0-9A-Fa-f]{1,4}){1,3}|::|:[0-9A-Fa-f]{1,4}(:(:[0-9A-Fa-f]{1,4}){1,2}|::|:[0-9A-Fa-f]{1,4}(::[0-9A-Fa-f]{1,4}|::|:[0-9A-Fa-f]{1,4}(::|:[0-9A-Fa-f]{1,4}))))))))|(:(:[0-9A-Fa-f]{1,4}){0,5}|[0-9A-Fa-f]{1,4}(:(:[0-9A-Fa-f]{1,4}){0,4}|:[0-9A-Fa-f]{1,4}(:(:[0-9A-Fa-f]{1,4}){0,3}|:[0-9A-Fa-f]{1,4}(:(:[0-9A-Fa-f]{1,4}){0,2}|:[0-9A-Fa-f]{1,4}(:(:[0-9A-Fa-f]{1,4})?|:[0-9A-Fa-f]{1,4}(:|:[0-9A-Fa-f]{1,4})))))):(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3})"
- else
- REGEX_ALL_ip4="`$RGXG cidr 0.0.0.0/0`" # all ip4
- REGEX_ALL_ip6="`$RGXG cidr ::/0`" # all ip6
- fi
- # GEOIP_service="geoip.ubuntu.com/lookup/" # only your IP
- # GEOIP_service="freegeoip.net/xml/" # all domain (it was open source, now https://ipstack.com )
- GEOIP_service="freegeoip.app/xml/" # all domain (fork of freegeoip.net)
- # GEOIP_service="freegeoip.app/json/"
- # GEOIP_service="freegeoip.app/csv/"
- # curl
- # -L, --location Follow redirects (H)
- # -s, --silent Silent mode (don't output anything)
- # -A, --user-agent STRING Send User-Agent STRING to server (H)
- curl -s -L -A "`basename $0`" $GEOIP_service$1 | grep -Eo "$REGEX_ALL_ip6|$REGEX_ALL_ip4" ; exit $?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement