<head>
<title>IP Geolocation plotter</title>
<!-- Load Prototype farmework -->
<script src=
"lib.js"
></script>
<script type=
"text/javascript"
>
var
sleeptime = 100;
var
toplot;
var
plotted;
var
unknown;
var
submit_button;
var
t_o;
function
plot_or_stop(){
if
(t_o)
{
shtop();
return
;
}
var
list = $(
'ip'
).value.split(/[\s,:;]+/);
if
(list[0].
empty
()) list.shift();
if
(list[list.length-1].
empty
()) list.pop();
toplot = document.getElementById(
"toplot"
).firstChild;
toplot.nodeValue = list.length;
plotted = document.getElementById(
"plotted"
).firstChild;
unknown = document.getElementById(
"unknown"
).firstChild;
submit_button = document.getElementById(
"submit"
);
if
(submit_button)
{
submit_button.old_value = submit_button.value;
submit_button.value =
"Stop"
;
}
plotnsleep( list, 0, sleeptime );
}
function
plotnsleep( list, offset, timeoutms )
{
t_o = null;
if
(offset >= list.length)
{
shtop();
return
;
}
plotip(list[offset]);
t_o = setTimeout(
function
() {
plotnsleep( list, offset+1, timeoutms )
}, timeoutms );
}
function
shtop()
{
if
(t_o)
{
clearTimeout(t_o);
t_o = null;
}
if
(submit_button)
{
submit_button.value = submit_button.old_value;
}
}
function
putonmap(txt,ip){
var
latlong = txt.split(
":"
);
var
point =
new
google.maps.LatLng(latlong[0],latlong[1]);
if
(isNaN(point.lat()))
{
unknown.nodeValue++;
}
else
{
var
marker =
new
google.maps.Marker({
map: map,
position: point,
flat:true});
marker.setTitle(ip +
" in "
+ latlong[2] +
" ("
+ latlong[0] +
","
+ latlong[1] +
")"
);
plotted.nodeValue++;
}
}
function
plotip(ip){
new
Ajax.Request(
'request.php?ip='
+ip,
{
method:
'get'
,
onSuccess:
function
(transport){
var
response = transport.responseText ||
"no response text"
;
putonmap(response,ip);
},
onFailure:
function
(){ alert(
'Something went wrong. Try calling request.php?ip=... manually.'
) }
});
}
</script>
</head>