Home | History | Annotate | Download | only in multinetwork
      1 #!/bin/bash
      2 
      3 nethandle=0
      4 
      5 readonly TEST_HOST="connectivitycheck.gstatic.com"
      6 readonly TEST_PATH="/generate_204"
      7 readonly PREFIX=">>>"
      8 
      9 function getUrls() {
     10     if [ ! -z $(echo "$1" | sed -e 's/[^:]//g') ]; then
     11         echo "http://[$1]$TEST_PATH"
     12         echo "http://[$1]:80$TEST_PATH"
     13     else
     14         echo "http://$1$TEST_PATH"
     15         echo "http://$1:80$TEST_PATH"
     16     fi
     17 }
     18 
     19 function toHex() {
     20     readonly local hexValue=$(bc -q 2>/dev/null << EOT
     21 obase=16
     22 $1
     23 EOT
     24 )
     25     if [ ! -z "$hexValue" ]; then
     26         echo "0x$hexValue"
     27     fi
     28 }
     29 
     30 
     31 if [ ! -z "$1" ]; then
     32     nethandle="$1"
     33 fi
     34 echo "$PREFIX Using nethandle $nethandle ($(toHex $nethandle))"
     35 echo ""
     36 
     37 readonly IPADDRESSES=$(
     38     adb shell /system/xbin/dnschk --nethandle $nethandle $TEST_HOST |
     39     sed -e 's/#.*//' -e '/^$/d')
     40 
     41 
     42 for host in $TEST_HOST $IPADDRESSES; do
     43     urls=$(getUrls $host)
     44     for url in $urls; do
     45         echo "$PREFIX Checking $url" >&2
     46         adb shell /system/xbin/httpurl --nethandle $nethandle "$url"
     47     done
     48 done
     49