Commit 2890cb65 authored by Olav Kvittem's avatar Olav Kvittem

IPv6 support for traceroute and iperf

parent 75c1180f
......@@ -31,7 +31,7 @@ function order(num, unit){
//--------------------------------------------------------------------------------
//
function iperf(direction, host, nobs, interval, parallel, port){
function iperf(direction, host, nobs, interval, parallel, port,ipprot){
if ( ! nobs ) nobs=10;
if (nobs > 100) {
nobs=100;
......@@ -42,7 +42,7 @@ function iperf(direction, host, nobs, interval, parallel, port){
if ( ! host) host="";
var title=true;
$("#busy").show();
var url='iperf-json.pl?host=' + host + '&nobs=' + nobs + '&interval=' + interval + "&direction=" + direction + '&parallel=' + parallel + '&port=' + port;
var url='iperf-json.pl?host=' + host + '&nobs=' + nobs + '&interval=' + interval + "&direction=" + direction + '&parallel=' + parallel + '&port=' + port + '&ipprot=' + ipprot;
console.log(url);
var bytes=[], thru=[]; series=[];
x_name=[document.location.host];
......@@ -179,6 +179,13 @@ html+= 'action="javascript:traceroute( $(\'#tr_host\').val(), $(\'#tr_times\').v
html2='<input id=tr_times value=3 style="width:3em;text-align:right"> times</input>';
html2+=', using <input id=tr_size value=64 style="width:3em;text-align:right"> bytes packets</input>';
html2+=', every <input id=tr_interval value=0.1 style="width:3em;text-align:right"> seconds.';
html2+=' on <select name=ipprot id=ipprot class="btn btn-primary btn-lg">';
html2+='<option value=ip>IP</options>';
html2+='<option value=ipv4>IPv4</options>';
html2+='<option value=ipv6>IPv6</options>';
html2+='</select>';
html2+='</table>';
html2+='</form>';
......@@ -235,13 +242,13 @@ function make_select( elm, url){
// html+= '<form name="iperf_form" id="iperf_form">';
// html+= '<select name="tr_opt" id="tr_opt">';
// html+= '<option value="">My host</option>';
var html='<form name="iperf_form" id="iperf_form"';
html+= 'action="javascript:iperf( $(\'#direction\').val(), $(\'#tr_host\').val(), $(\'#tr_times\').val(), $(\'#tr_interval\').val(), $(\'#tr_parallel\').val(), $(\'#tr_port\').val() )">';
var html='<form name="iperf_form" id="iperf_form" class = "form-horizontal" role = "form"';
html+= 'action="javascript:iperf( $(\'#direction\').val(), $(\'#tr_host\').val(), $(\'#tr_times\').val(), $(\'#tr_interval\').val(), $(\'#tr_parallel\').val(), $(\'#tr_port\').val(), $(\'#ipprot\').val() )">';
html+='<table><tr><td>';
html+='<input class="btn btn-primary btn-lg" type="submit" value="Test" class=button/> ';
html+='<select id=direction style=width=6em><option value="to">to</option><option value="from">from</option></select>';
html+='<select id=direction style=width=6em class="btn-primary"><option value="to">to</option><option value="from">from</option></select>';
html+='<td><input id=tr_host value="" placeholder="my host" title="Automatic completion(try \'mp\')"></input>';
html+='<select id=tr_host_menu title="Choose host">host menu</select>';
html+='<select id=tr_host_menu title="Choose host" class="btn-primary">host menu</select>';
// html+='<span id=select-house></span>';
var html2=' <td> &nbsp;';
html2+=' for <input id=tr_times value=5 style="width:2em;text-align:right"> seconds</input>';
......@@ -249,6 +256,13 @@ function make_select( elm, url){
html2+=', report every <input id=tr_interval value=0.5 style="width:2em;text-align:right"> seconds';
html2+=', with <input id=tr_parallel value="1" title="Number of parallel sessions" style=width:1em></input> parallels ';
html2+='on port <input id=tr_port value="5001" title="Default port for iperf3 is 5201" style=width:3em></input>';
html2+=' using <select name=ipprot id=ipprot class="btn-primary">';
html2+='<option value=ip>IP</options>';
html2+='<option value=ipv4>IPv4</options>';
html2+='<option value=ipv6>IPv6</options>';
html2+='</select>';
html2+='</table>';
html2+='</form>';
// html+='<button id="toggle">Show menu</button>';
......
......@@ -38,12 +38,14 @@ if ( $q->http('HTTP_X_TOKEN') ne "virre-virre-vapp" ){
my $port = $q->param('port'); # && ( psize =~ m/^[0-9]+$/ );
my $interval = $q->param('interval'); # && ( psize =~ m/^[0-9]+$/ );
my $direction = $q->param('direction');
my $ipprot = $q->param('ipprot');
$host =~ s/[^a-zA-ZæøåÆØÅ0-9\.\/\-_\:]+/_/g; # protect
$nobs =~ s/[^0-9]+/_/g;
$psize =~ s/[^0-9]+/_/g;
$port =~ s/[^0-9]+/_/g;
$parallel =~ s/[^0-9]+/_/g;
$direction =~ s/[^a-zA-ZæøåÆØÅ0-9\.\/\-_]+/_/g;
$ipprot =~ s/[^a-zA-ZæøåÆØÅ0-9\.\/\-_]+/_/g;
$host = $q->remote_host if $host eq "";
$nobs = 3 if $nobs < 1;
......@@ -57,7 +59,14 @@ if ( $q->http('HTTP_X_TOKEN') ne "virre-virre-vapp" ){
} else {
$dirparm="";
}
my $cmd= "/usr/local/bin/iperf3 -i $interval -t $nobs -c $host -P $parallel -p $port --json $dirparm";
my $ipopt='';
if($ipprot eq "ipv4"){
$ipopt='-4';
} elsif($ipprot eq "ipv6"){
$ipopt='-6';
}
my $cmd= "/usr/local/bin/iperf3 -i $interval -t $nobs -c $host -P $parallel -p $port --json $dirparm $ipopt";
# open MTR, $cmd || die "Could not open : $cmd : $!";
......
......@@ -5,7 +5,7 @@ function make_select( elm, url, heading){
var html='';
// commented code is to produce a select_menu rather than jquery ui autocomplete
html+= '<form name="traceroute_form" id="traceroute_form">';
html+= '<select name="mp_opt" id="mp_opt" class="btn btn-basic btn-lg" onChange="top.location.href = this.form.mp_opt.options[this.form.mp_opt.selectedIndex].value;return false;">';
html+= '<select name="mp_opt" id="mp_opt" class="btn-primary" onChange="top.location.href = this.form.mp_opt.options[this.form.mp_opt.selectedIndex].value;return false;">';
html+= '<option value="">' + heading +'</option>';
var items=[];
......
......@@ -19,7 +19,7 @@ function make_table(mtr_rows){
//--------------------------------------------------------------------------------
//
function traceroute(host, nobs, psize, interval){
function traceroute(host, nobs, psize, interval, ipprot){
if ( ! nobs ) nobs=10;
// resistance to big number overflow and DOS attacks
if (nobs > 100) {
......@@ -36,7 +36,8 @@ function traceroute(host, nobs, psize, interval){
var title=true;
$("#busy").show();
// var url='http://fou1.uninett.no/cgi-bin/traceroute.pl?host=' + host + '&nobs=' + nobs + '&psize=' + psize + '&interval=' + interval;
var url='traceroute.pl?host=' + host + '&nobs=' + nobs + '&psize=' + psize + '&interval=' + interval;
var url='traceroute.pl?host=' + host + '&nobs=' + nobs + '&psize=' + psize + '&interval=' + interval
+ '&ipprot=' + ipprot;
console.log(url);
var avg=[0], loss=[0], best=[0], wrst=[0], stdev=[0];
x_name=[document.location.host];
......@@ -125,14 +126,20 @@ function make_select( elm, url){
// html+= '<form name="traceroute_form" id="traceroute_form">';
// html+= '<select name="tr_opt" id="tr_opt">';
// html+= '<option value="">My host</option>';
var html='<form name="traceroute_form" id="traceroute_form"';
html+= 'action="javascript:traceroute( $(\'#tr_host\').val(), $(\'#tr_times\').val(), $(\'#tr_size\').val(), 1 /* $(\'#tr_interval\').val()*/ )">';
var html='<form name="traceroute_form" id="traceroute_form" class = "form-horizontal" role = "form"';
html+= 'action="javascript:traceroute( $(\'#tr_host\').val(), $(\'#tr_times\').val(), $(\'#tr_size\').val(), 1 /* $(\'#tr_interval\').val()*/, $(\'#ipprot\').val() )">';
html+='<table><tr><td>';
html+='<input type="submit" value="Trace route" class="btn btn-primary btn-lg" /> to ';
html+='<input id=tr_host value="" placeholder="my host" title="Automatisk utfylling av målepålenavn"></input>';
var html2=' <td> &nbsp;';
html2='<input id=tr_times value=3 style="width:3em;text-align:right"> times</input>';
html2+=', using <input id=tr_size value=64 style="width:3em;text-align:right"> bytes packets.</input>';
html2+=', using <input id=tr_size value=64 style="width:3em;text-align:right"> bytes packets </input>';
html2+=' on <select name=ipprot id=ipprot class="btn-primary">';
html2+='<option value=ip>IP</options>';
html2+='<option value=ipv4>IPv4</options>';
html2+='<option value=ipv6>IPv6</options>';
html2+='</select>';
//ok html2+=', every <input id=tr_interval value=0.1 style="width:3em;text-align:right"> seconds.';
html2+='</table>';
html2+='</form>';
......
......@@ -31,6 +31,7 @@ if ( $q->http('HTTP_X_TOKEN') ne "virre-virre-vapp"){
my $nobs = $q->param('nobs'); # && ( $nobs =~ m/^[0-9]+$/ );
my $psize = $q->param('psize'); # && ( psize =~ m/^[0-9]+$/ );
my $interval = $q->param('interval'); # && ( psize =~ m/^[0-9]+$/ );
my $ipprot = $q->param('ipprot');
$host =~ s/[^a-zA-ZæøåÆØÅ0-9\.\/\-_\:]+/_/g; # protect
$nobs =~ s/[^0-9]+/_/g;
$psize =~ s/[^0-9]+/_/g;
......@@ -39,9 +40,16 @@ if ( $q->http('HTTP_X_TOKEN') ne "virre-virre-vapp"){
$nobs = 3 if $nobs < 1;
$psize = 64 if $psize < 1;
$interval= 0.1 if $interval <= 0;
my $ipopt='';
if($ipprot eq "ipv4"){
$ipopt='-4';
} elsif($ipprot eq "ipv6"){
$ipopt='-6';
}
# my $cmd= "/usr/bin/mtr -c $nobs -s $psize -i $interval --report --report-wide $host";
# mtr does not like interval less than 1sek from nonroot and therefore purposeless
my $cmd= "/usr/bin/mtr -c $nobs -s $psize --report --report-wide $host";
my $cmd= "/usr/bin/mtr -c $nobs -s $psize --report --report-wide $host $ipopt";
# open MTR, $cmd || die "Could not open : $cmd : $!";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment