Jump to content

IPv6


JRSmile
 Share

Recommended Posts

Hi there im currently learning for my exams and this is what i came up with implementing the mapping function of the rfc conform ipv4 to ipv6 conversion.

#include <string.au3>
ConsoleWrite(@IPAddress4 & @CRLF)
ConsoleWrite(__CIDR2Dotted(96) & @CRLF)
ConsoleWrite(__bitmask2IP(_StringRepeat("0",80)&_StringRepeat("1",16) & ip2bit(@IPAddress4)) & @CRLF)


Func ip2bit($ip)
    $tmp2 = StringSplit($ip,".", 1)
    Local $tmp4
    for $i = 1 to $tmp2[0]
        $tmp3 = Hex($tmp2[$i],2)
        $tmp3 = StringSplit($tmp3,"",1)
        $tmp4 &= cov($tmp3[1]) & cov($tmp3[2])
        
    Next
    Return $tmp4
EndFunc

Func cov($hex)
    Switch $hex
        Case "0"
            Return "0000"
        Case "1"
            Return "0001"
        Case "2"
            Return "0010"
        Case "3"
            Return "0011"
        Case "4"
            Return "0100"
        Case "5"
            Return "0101"
        Case "6"
            Return "0110"
        Case "7"
            Return "0111"
        Case "8"
            Return "1000"
        Case "9"
            Return "1001"
        Case "A"
            Return "1010"
        Case "B"
            Return "1011"
        Case "C"
            Return "1100"
        Case "D"
            Return "1101"
        Case "E"
            Return "1110"
        Case "F"
            Return "1111"
    EndSwitch
EndFunc

Func __CIDR2Dotted($cidr)
    $part = _StringRepeat("1",$cidr)
    Return __bitmask2IP($part)
EndFunc

Func __bitmask2IP($string)
    $string = StringStripWS($string,8)
    Local $res = ""
    $string = $string & StringTrimLeft(_StringRepeat("0",128), StringLen($string))
    ConsoleWrite($string & @CRLF)
    for $i = 1 to StringLen($string) step 16
        $part = StringMid($string,$i,16)
        $res &= conv_part($part) & ":"
    Next
    Return StringTrimRight($res,1)
EndFunc



Func conv_part($src)
    if StringLen($src) <> 16 then Return SetError(1,0,False)
    if not IsString($src) Then Return SetError(1,0,False)
    $src = StringSplit($src,"", 1)
    Local $res = 0
    for $i = 1 to 16
        $res += 2^(16-$i) * $src[$i]
    Next
    Return Hex($res,4)
EndFunc

i think its nasty and universes far away from beeing perfect, if somebody has a plan how to improove my funcs, maybe with math, and explain a bit about bit operation i would be glad.

Best regards,

JR.

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Link to comment
Share on other sites

a short func here for you

Func cov($Hex)
    Local $aVals[16] = ["0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"]
    Return $aVals[Dec($Hex)]
EndFunc
My Scripts[topic="73325"]_ReverseDNS()[/topic]Favourite scripts by other members[topic="81687"]SNMP udf[/topic][topic="70759"]Using SNMP - MIB protocol[/topic][topic="39050"]_SplitMon:Section off your monitor!, split your monitor into sections for easy management[/topic][topic="73425"]ZIP.au3 UDF in pure AutoIt[/topic][topic="10534"]WMI ScriptOMatic tool for AutoIt[/topic][topic="51103"]Resources UDF embed/use any data/files into/from AutoIt compiled EXE files[/topic]
Link to comment
Share on other sites

i did a even more dirty implementation ^_^

Func small_conv($ip)
    $ip = StringSplit($ip, ".", 1)
    Return "0000:0000:0000:0000:0000:FFFF:" & Hex($ip[1], 2) & Hex($ip[2], 2) & ":" & Hex($ip[3], 2) & Hex($ip[4], 2) & "/96"
EndFunc   ;==>small_conv

but this is crap ;)

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Link to comment
Share on other sites

@JRSMile

I had this on my to do list, but never came around starting it.

I did some quick checks for an IP address : 10.0.0.71

On the client it reads, using IPCONFIG : fe80::20f:b0ff:fe40:ca8f%5

On the online convertor I other data ?

Online Convertor

This address is an IPv4 address:

IP v4 :

decimal : 10.0.0.71

binary : 00001010000000000000000001000111

octal : 012.00.00.0107

hexadecimal : 0x0A.0x00.0x00.0x47

long : 167772231

IP v6 :

6 to 4 address : 2002:A00:47:0:0:0:0:0

: 2002:A00:47::

IPv4-mapped address : 0:0:0:0:0:FFFF:10.0.0.71

: ::FFFF:10.0.0.71

: ::FFFF:0A00:0047

IPv4-compatibility address : 0:0:0:0:0:0:10.0.0.71

: ::10.0.0.71

: ::0A00:0047

So there seems to be different type of notations going round ?

Which makes it more confusing. ^_^

Regards

ptrex

Link to comment
Share on other sites

there is just one standart definded in http://tools.ietf.org/html/rfc4291#section-2.5.5

the rest is more ore less "weak acceptance".

there was an old but deprecated way to map ips just leave the first 96 bytes empty and add the ipv4 behind...

but this got declined later.

you now have to send 80bytes of zeros 16 bytes of ones and then the ipv4 address as hex value spread over two WORDs.

so you can implement it correctly ^_^ << fortunately otherwise there won't be any implementation at all ;)

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...