create csv/excel IPv6 subnet

Reference: http://colinrrobinson.com/technology/programming/php/ipv6-subnet-calculator/

 

  1. download source
  2. modify calculator_tools.php, add following function
    function print_csv( $network )
    {
            if (substr_count($network->position, '.') == 1){
            	echo $network->position.',56,';
    	}else{
            	echo $network->position.',64,';
    	}
    
            if ( count($network->subnets) )
                    echo '';
    
            echo hex_to_human($network->ip) . '/' . $network->prefix . "\n";
    
            foreach( $network->subnets as $subnet )
                    $network_array['subnets'][] = print_csv($subnet); 
    }

     

  3. add create_csv.php
    <?php
    require_once 'calculator_tools.php';
    require_once 'Network.php';
    
    $address = '2001:b000:0015::';
    $prefix  = '48';
    $levels  = array('256','256');
    
    $ip = human_to_hex( $address );
    $network = new Network($ip, $prefix, $levels);
    print_csv($network);
    
    ?>

     

Facebook Comments Box

Leave a Reply