After I discovered the traceroute command on *NIX systems, my natural instinct was to plot it on a map. This was the first real Bash program I wrote and oh boy will it be my last. I spent like 45 minutes trying to debug something that ended up being an extra whitespace character somewhere.

read more
#!/bin/bash

##OUTPUT=[$(traceroute 192.168.1)]
##OUTPUT=[$(traceroute www.globo.com)]
OUTPUT=[$(traceroute www.dw.de)]
##OUTPUT=[$(traceroute www.canada.gc.ca)]
##OUTPUT=[$(traceroute europa.e)]
COUNT=0
IPS=()
for ITEM in $OUTPUT
do
	if [[ $ITEM == \(* ]] 
	then 
		
		IPS[$COUNT]=$ITEM
		COUNT=$(($COUNT + 1))
		
	fi
	
done


COUNT=0

for ITEM in "${IPS[@]}" 
do
	
	TEMP=$ITEM
	TEMPLEN=${#ITEM}
	TEMPLEN=$(($TEMPLEN - 2))
	IPS[$COUNT]=${ITEM:1:TEMPLEN}
	COUNT=$(($COUNT + 1))	

done

INDEX=0
LATITUDES=()
LONGITUDES=()
ENDURL="http://maps.google.com/maps/api/staticmap?sensor=true¢er=Raleigh,NC&zoom=2&size=2000x2000&maptype=roadmap"

for ITEM in "${IPS[@]}" 
do
	
	INFO=$(curl -s http://api.hostip.info/get_html.php?ip=$ITEM\&position=true)
	##echo $INFO
	spo="$INFO"
	OIFS=$IFS
	IFS=':'
	spo_array=($spo)
	IFS=$OIFS
	
	LAT=${spo_array[3]}
	LONG=${spo_array[4]}
	
	MAN="$LAT"
	NAM="$LONG"
	##IFS=" "
	LAT_array=($MAN)
	LONG_array=($NAM)
	##IFS=$OIFS

	##If these elements do not equal Longitude and IP respectively, then we add them to the
	##list of things to plot. We also need to remove duplicates so we'll check for that. 
	FINALAT=${LAT_array[0]}
	FINALONG=${LONG_array[0]}

	if [[ $FINALAT != "Longitude" && $FINALONG != "IP" ]]; 
	then 
		NUMBER=$(($INDEX - 1))
		PASTLAT=${LATITUDES[$NUMBER]}
		PASTLONG=${LONGITUDES[$NUMBER]}
		if [[ $PASTLAT != $FINALAT && $PASTLONG != $FINALONG ]]; 
		then 
			LATITUDES[$INDEX]=$FINALAT
			LONGITUDES[$INDEX]=$FINALONG
			INDEX=$(($INDEX + 1))
			ENDURL="$ENDURL&markers=color:green|label:$INDEX|${FINALAT},${FINALONG}"
		fi
		##echo $FINALAT
		##echo $FINALONG
	fi  
	


	
done

python -mwebbrowser "$ENDURL&sensor=false"


##http://maps.google.com/maps/api/staticmap?center=New+York,NY&zoom=2&size=2000x2000&maptype=roadmap&markers=color:blue|label:S|50.702147,-74.015794&markers=color:green|##label:G|40.711614,-74.012318&markers=color:red|color:red|label:C|40.718217,-73.998284&sensor=false&key=MAPS_API_KEY