APNIC

Labs

Advanced Scripting

It is possible to add additional features to this script. The basic form of the script just sets the variable 'ipproto_user' to a user value. It is possible to alter the invocation on the javascript on the web page to invoke additional tests and alter the behaviour of the script. The full set of parameters is shown in the following alternative script invocation:

// enable the APNIC IPProtoTest and feed google analytics events
  if ('http:' == document.location.protocol) {

   var ipproto_user = '111111';          // the user variable provided at http://labs.apnic.net
                                        // default state of the options.
   var ipproto_opts = {
     'docookies'        : true,         // test based on noCheckInterval in cookie
     'noCheckInterval'  : 86400000,     // interval to test on, if docoookies is true
     'dov6dns'          : true,         // test v6 dns to a dual-stack URL
     'dov6literal'      : true,         // test a v6 literal URL
     'dotunnels'        : false,        // test for 6to4 and teredo tunnels
     'randomize'        : false,        // by default, sorted test order
     'sampling'         : 1,            // 1/sampling eg sampling=4 1/4th tested
     'userId'           : ipproto_user, // what to log in the collector website 
     'callback'         : function_name // prototype function to receive callback of results
   };

Default values

docookies

The default value of this variable is "true". If docookies is set to "false", the test will be performed every time each client visits this web page. This may bias your analytics reports towards the IPv6 capabilities of the most frequent visitors to the site. If docookies is set to "true", then the client is loaded with an object that controls the frequency of execution of this test for each client.

noCheckInterval

The default value of the test frequency is once per day for each client. This can be adjusted by setting noCheckInterval to a frequency time. The unit is milliseconds, so that one day (the default value) is 86400000. The default value of this variable is, therefore, 86400000.

dov6dns

The default value of this variable is "true". If dov6dns is set to "true", the script will test if the client is able to cause DNS names to be resolved using DNS queries over IPv6 transport. If dov6dns is set to "false", this test will not be performed.

dov6literal

The default value of this variable is "true". If dov6literal is set to "true", the script will test if the client is able to retrieve an object where the domain name part of the URL is an IPv6 address literal. This test is used to expose latent Teredo capabilities on Windows hosts, where the host will not normally query the DNS for AAAA records of the only IPv6 interface on a Teredo auto-tunnel interface. If dov6literal is set to "false", this test will not be performed.

dov6tunnels

The default value of this variable is "false". If dov6tunnels is set to "true", the script will include a further two tests to determine which auto-tunnel mechanism the client is using. The event v6stf will record the incidence of 6to4 auto-tunnelling by clients, and the event v6ter will record the incidence of Teredo auto-tunnelling by clients.

randomize

If randomize is set to "true", the order in which the client performs the tests will be randomized. If this variable is set to "false", the order of the tests will be as follows:

1. v6-only, 2. Dual-Stack 3. v4-only 4. v6 DNS (if enabled) 5. v6 Literal (if enabled) 6. v6-only with 6to4 (if enabled) 7. v6-only with Teredo (if enabled)

sampling

If sampling is set to a value, the test will be performed at random at a rate of 1 in sampling times. The default value of this variable is 1. This means the test is performed every time the script is invoked, depending on the cookie state.

userid

The userId is a value provided by the enrollment page at labs.apnic.net. This allows like web pages to be grouped together. The variable is optional, and the default value is 0 (anonymous).

callback

The callback variable is a function name to be called when the tests have been completed. This can be used to report back to the user on the results of the tests. The default value of this variable is no callback. When using callback, note that this script has a timeout of 10 seconds. This means the script will wait for 10 seconds before reporting the test results and invoking the callback function.

An example of using these settings to perform a rudimentary callback is in the following code:

<html>

  <head>
    <title>ipv6-test</title>
</head>

  <body>
    <h1>ipv6-test</h1>

 <body bgcolor=#FFFFFF>

 <div>
    <div> IPv4: <span id='ipprototest_ok_r4td'></span> </div>

    <div> IPv6: <span id='ipprototest_ok_r6td'></span> </div>
    <div> Dual: <span id='ipprototest_ok_rdtd'></span> </div>

    <div> 6dns: <span id='ipprototest_ok_rdt6'></span> </div>
    <div> 6lit: <span id='ipprototest_ok_v6lit'></span> </div>

    <div>  stf: <span id='ipprototest_ok_v6stf'></span> </div>
    <div>  ter: <span id='ipprototest_ok_v6ter'></span> </div>

    <div> IPv4 Speed: <span id='ipprototest_speed_r4td'> </span> </div>
    <div> IPv6 Speed: <span id='ipprototest_speed_r6td'> </span> </div>

    <div> Dual Speed: <span id='ipprototest_speed_rdtd'> </span> </div>

    <div> 6dns Speed: <span id='ipprototest_speed_rdt6'> </span> </div>

    <div> 6lit Speed: <span id='ipprototest_speed_v6lit'> </span> </div>
    <div>  stf Speed: <span id='ipprototest_speed_v6stf'> </span> </div>

    <div>  ter Speed: <span id='ipprototest_speed_v6ter'> </span> </div>
 </div>

<script type="text/javascript">

  // for all possible tests, update an _ok and a _speed entry in HTML 
  function results(r) {
		  // complete test set. 
        var tests = ['r4td','r6td','rdtd','rdt6','v6lit','v6stf','v6ter'];
        for(var i=0;i<tests.length;i++) {
            var x = tests[i];
		        var innerDiv;
		        if ( innerDiv = document.getElementById('ipprototest_ok_' + x) ) {
		    if ( r[x] === false ) {
		        innerDiv.innerHTML = 'failed';
		    } else if ( r[x] ) {
		        innerDiv.innerHTML = 'OK';
		    } else {
		        innerDiv.innerHTML = 'not tested';
		    }
		        }
		        if ( innerDiv = document.getElementById('ipprototest_speed_' + x) ) {
		    if ( r[x] === false ) {
		        innerDiv.innerHTML = 'failed';
		    } else if ( r[x] ) {
		        innerDiv.innerHTML = r[x] + 'ms';
		            } else {
		        innerDiv.innerHTML = 'n/a';
		            }
		        }
		    }
  }

  // initialize google analytics
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-597837-4']);  // google analytics account
  _gaq.push(['_setDomainName', 'www.cidr-report.org']);  // domain being tracked

  (function() {
   var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
   ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
  })();

// enable the APNIC IPProtoTest and feed google analytics events
  if ('http:' == document.location.protocol) {

   // setting the options
   var ipproto_opts = {
     'docookies'        : false,       // test based on noCheckInterval in cookie
     'noCheckInterval'  : 86400000,    // interval to test on, if docoookies is true
     'dov6dns'          : true,        // test v6 dns to a dual-stack URL
     'dov6literal'      : true,        // test a v6 literal URL
     'dotunnels'        : true,        // test for 6to4 and teredo tunnels
     'randomize'        : true,        // by default, sorted test order
     'sampling'         : 1,           // 1/sampling eg sampling=4 1/4th tested
     'userId'           : '123456',    // what to log in the collector website 
     'callback'         : results      // prototype function to receive callback of results
   };

   (function() {
    var iga = document.createElement('script'); iga.type = 'text/javascript'; iga.async = true; 
    iga.src = 'http://labs.apnic.net/ipprototesto.js';
    var is = document.getElementsByTagName('script')[0]; is.parentNode.insertBefore(iga, is); 
   })();
  }

</script>
</body>
</html>