#! /bin/bash
# ideally one would shuffle all size*repetition to better average out transient issues
#
# USEAGE
# 1) use "traceroute 8.8.8.8" and find the network hops just outside of your modem
# 	typically for ATM the modem to DSLAM link will introduce an additional >10ms latency 
#	so the hop directly after the first big latency jump should be close to the DSLAM, use 
#	this hops IP address should be used as TARGET below
# 2) optional confirm this IPs reliability by running "ping -c 100" against this IP
#	the min and max of the ping times should stay close to the average and the stddev
#	 should be small as well, otherwise PINGSPERSIZE might need to be set to >=100
#

TECH=CABLE		# CABLE, ATM, ... just to name the log file
DATESTR=`date +%Y%m%d_%H%M%S`	# to allow multiple sequential records
TARGET=96.34.97.78				# use traceroute something far to get the first hop out of the home net
LOG=ping_sweep_${TECH}_${DATESTR}.txt


PINGSPERSIZE=50		# 480 packet sizes take 13.33 hours at 100 repetitions, so stick to 50
SWEEPMINSIZE=16		# on macosx 10.7 64bit, sizes < 16 do not have a timestamp...
SWEEPMAXSIZE=496	# initial size plus 10 full ATM cells (of 48 bytes payload each)
n_SWEEPS=`expr ${SWEEPMAXSIZE} - ${SWEEPMINSIZE}`

# do it
echo "Sweeping ${n_SWEEPS} * ${PINGSPERSIZE} pings to ${TARGET} might take a while..."
echo "ping -c ${PINGSPERSIZE} -g ${SWEEPMINSIZE} -G ${SWEEPMAXSIZE} ${TARGET} > ${LOG}"
ping -c ${PINGSPERSIZE} -g ${SWEEPMINSIZE} -G ${SWEEPMAXSIZE} ${TARGET} > ${LOG} &

# show some progress
tail -f ${LOG}

echo "Done... ($0)
"