Skip to content

Instantly share code, notes, and snippets.

@miticojo
Last active September 22, 2019 13:31
Show Gist options
  • Save miticojo/5feb93b5b19a69e53f3de6da886636ab to your computer and use it in GitHub Desktop.
Save miticojo/5feb93b5b19a69e53f3de6da886636ab to your computer and use it in GitHub Desktop.
#!/bin/bash
APIURL=https://speech.googleapis.com
REMOTEIP=$(curl -s ipinfo.io/ip)
REMOTEASN=$(curl -s ipinfo.io/org | cut -d' ' -f1)
RESULTFILE="google-ping-api-results-$(date +%s).csv"
## Script start time
START=$(date +%s)
## Total run time
DURRATION=$((60 * 60 * 24))
## Total running time
UPTIME=$(($(date +%s) - $START))
echo "=========================================="
echo "Starting 24h connection test to $APIURL..."
echo "Results are written into $RESULTFILE"
echo "=========================================="
sleep 2
(
echo "timestamp,remote_ip,remote_asn,time_namelookup,time_connect,time_appconnect,time_pretransfer,time_redirect,time_starttransfer,time_total"
while [[ $UPTIME -le $DURRATION ]]; do
curl -s -o /dev/null \
-w "%{time_namelookup},%{time_connect},%{time_appconnect},%{time_pretransfer},%{time_redirect},%{time_starttransfer},%{time_total}\n" \
$APIURL | xargs -L 1 echo "$(date +'%s'),$REMOTEIP,$REMOTEASN,$1"
## Sleep for a bit
sleep 2
## Update running time
UPTIME=$(($(date +%s) - $START))
done
) | tee $RESULTFILE
echo "=========================================="
echo "Connection test completed with success. Please send back the results file $RESULTFILE for analisys."
@miticojo
Copy link
Author

miticojo commented Sep 21, 2019

Results should be like these:

==========================================
Starting 24h connection test to https://speech.googleapis.com...
Results are written into google-ping-api-results-1569159026.csv
==========================================
timestamp,remote_ip,remote_asn,time_namelookup,time_connect,time_appconnect,time_pretransfer,time_redirect,time_starttransfer,time_total
1569159028,94.36.138.115,AS8612, 0.069483,0.087984,0.154431,0.154663,0.000000,0.247622,0.247815
1569159030,94.36.138.115,AS8612, 0.005061,0.024868,0.089130,0.089309,0.000000,0.178536,0.178839
1569159032,94.36.138.115,AS8612, 0.004653,0.025061,0.084069,0.084303,0.000000,0.176173,0.177323
1569159035,94.36.138.115,AS8612, 0.005067,0.022549,0.082267,0.082852,0.000000,0.127773,0.127840
1569159037,94.36.138.115,AS8612, 0.005082,0.022518,0.084950,0.085147,0.000000,0.130299,0.130496
1569159039,94.36.138.115,AS8612, 0.005068,0.023441,0.084819,0.085021,0.000000,0.175390,0.177764
1569159041,94.36.138.115,AS8612, 0.005055,0.023009,0.086726,0.086912,0.000000,0.177742,0.177940
1569159043,94.36.138.115,AS8612, 0.005083,0.022770,0.085065,0.085223,0.000000,0.182955,0.183085
1569159046,94.36.138.115,AS8612, 0.004173,0.023112,0.083997,0.084166,0.000000,0.149201,0.149275
1569159048,94.36.138.115,AS8612, 0.004991,0.022580,0.084150,0.084280,0.000000,0.194319,0.195076
1569159050,94.36.138.115,AS8612, 0.004093,0.025208,0.087483,0.087623,0.000000,0.139029,0.139179
1569159052,94.36.138.115,AS8612, 0.004643,0.023519,0.089962,0.090086,0.000000,0.135782,0.135902
1569159054,94.36.138.115,AS8612, 0.004546,0.025664,0.087561,0.087675,0.000000,0.175278,0.176115
1569159057,94.36.138.115,AS8612, 0.004216,0.021663,0.085309,0.085495,0.000000,0.176312,0.177130
1569159059,94.36.138.115,AS8612, 0.004986,0.023615,0.086545,0.086670,0.000000,0.176491,0.177406
1569159061,94.36.138.115,AS8612, 0.005063,0.024059,0.088059,0.088241,0.000000,0.138373,0.138561
1569159063,94.36.138.115,AS8612, 0.004072,0.023627,0.088485,0.088823,0.000000,0.182960,0.183171
1569159065,94.36.138.115,AS8612, 0.005062,0.023756,0.082959,0.083135,0.000000,0.175411,0.175614
1569159068,94.36.138.115,AS8612, 0.005061,0.024741,0.085330,0.085529,0.000000,0.182129,0.182649
1569159070,94.36.138.115,AS8612, 0.005060,0.023628,0.087932,0.088112,0.000000,0.180463,0.180651
1569159072,94.36.138.115,AS8612, 0.004409,0.022005,0.083809,0.083970,0.000000,0.129474,0.130307
1569159074,94.36.138.115,AS8612, 0.005063,0.023669,0.086059,0.086409,0.000000,0.132135,0.132749
1569159076,94.36.138.115,AS8612, 0.005087,0.022721,0.089673,0.089876,0.000000,0.192545,0.193344
1569159079,94.36.138.115,AS8612, 0.004475,0.025318,0.087830,0.088061,0.000000,0.180756,0.180969
1569159081,94.36.138.115,AS8612, 0.004229,0.022686,0.088220,0.088413,0.000000,0.182119,0.182612
1569159083,94.36.138.115,AS8612, 0.005056,0.025445,0.089410,0.089594,0.000000,0.179148,0.179623

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment