#!/usr/bin/perl # buildipv6 is provided by Ph03n1X # Really nasty code but work :) use strict; use warnings; my $LOGFILE="./logs/ipv6.out"; sub str2hex() { #Sub routine str2hex my($bit) = @_; my ($bitlo,$bithi); if($bit =~ /-/){ my @atbit=split('-',$bit); if(hex($atbit[0]) > hex($atbit[1])){ print "ERR! Hexal value at right of \'-\' must be higher than at left\n"; exit; } $bitlo = $atbit[0]; $bithi = $atbit[1]; }else{ $bitlo= $bit; $bithi= $bit; } return($bitlo,$bithi); } #End of sub routine str2hex #Routine main if(!$ARGV[0]){ print "USAGE:\n"; print "build []\n"; print ""; print "Ex=> run 2046:f0af-f0ff:0a0a:c000-c010:0:0:0:0\n"; print "Ex=> run fe80:0:0:0:201:6cff:fe9e:e6ab-e6ff\n\n"; print "ATTENTION!\n"; print "1. You have to enter all 128-bit and can not use \'::\'\n"; print "2. Hexal value at right of \'-\' must be higher than at left\n"; print "3. Don\'t create address range at the first 64-bit of address link scope\n"; print "4. Make sure that 17-bit till 64-bit after link scope is 0\n"; print "5. Read RFC 3513 to make sure you know what you do\n"; print "This code doesn\'t handle all error caused by not following this!\n"; exit; } my $iface; if(!$ARGV[1]){ $iface="%eth0"; }else{ $iface="%" . $ARGV[1]; } my ($c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8); open(IPv6,">$LOGFILE"); my @allbit = split(':',$ARGV[0]); if (scalar(@allbit) !=8){ print "ERR! You have to enter all 128-bit and can not use \'::\'\n"; exit; } my $bit1 = $allbit[0]; my $bit2 = $allbit[1]; my $bit3 = $allbit[2]; my $bit4 = $allbit[3]; my $bit5 = $allbit[4]; my $bit6 = $allbit[5]; my $bit7 = $allbit[6]; my $bit8 = $allbit[7]; my ($bit1lo,$bit1hi) = &str2hex($bit1); my ($bit2lo,$bit2hi) = &str2hex($bit2); my ($bit3lo,$bit3hi) = &str2hex($bit3); my ($bit4lo,$bit4hi) = &str2hex($bit4); my ($bit5lo,$bit5hi) = &str2hex($bit5); my ($bit6lo,$bit6hi) = &str2hex($bit6); my ($bit7lo,$bit7hi) = &str2hex($bit7); my ($bit8lo,$bit8hi) = &str2hex($bit8); #printf("high bit = %X dan low bit = %X\n",hex($bit1hi),hex($bit1lo)); #printf("high bit = %X dan low bit = %X\n",hex($bit2hi),hex($bit2lo)); #printf("high bit = %X dan low bit = %X\n",hex($bit3hi),hex($bit3lo)); #printf("high bit = %X dan low bit = %X\n",hex($bit4hi),hex($bit4lo)); #printf("high bit = %X dan low bit = %X\n",hex($bit5hi),hex($bit5lo)); #printf("high bit = %X dan low bit = %X\n",hex($bit6hi),hex($bit6lo)); #printf("high bit = %X dan low bit = %X\n",hex($bit7hi),hex($bit7lo)); #printf("high bit = %X dan low bit = %X\n",hex($bit8hi),hex($bit8lo)); for($c1=hex($bit1lo);$c1<=hex($bit1hi);$c1++){ for($c2=hex($bit2lo);$c2<=hex($bit2hi);$c2++){ for($c3=hex($bit3lo);$c3<=hex($bit3hi);$c3++){ for($c4=hex($bit4lo);$c4<=hex($bit4hi);$c4++){ for($c5=hex($bit5lo);$c5<=hex($bit5hi);$c5++){ for($c6=hex($bit6lo);$c6<=hex($bit6hi);$c6++){ for($c7=hex($bit7lo);$c7<=hex($bit7hi);$c7++){ for($c8=hex($bit8lo);$c8<=hex($bit8hi);$c8++){ if($c1==65152){ printf ("%X:%X:%X:%X:%X:%X:%X:%X%s\n",$c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8,$iface); printf (IPv6 "%X:%X:%X:%X:%X:%X:%X:%X%s\n",$c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8,$iface); }else{ printf ("%X:%X:%X:%X:%X:%X:%X:%X\n",$c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8); printf (IPv6 "%X:%X:%X:%X:%X:%X:%X:%X\n",$c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8); } } } } } } } } } #End of routine main