JRSmile Posted April 23, 2009 Posted April 23, 2009 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. expandcollapse popup#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:-)
rogdog Posted April 23, 2009 Posted April 23, 2009 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]
JRSmile Posted April 23, 2009 Author Posted April 23, 2009 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:-)
ptrex Posted April 23, 2009 Posted April 23, 2009 @JRSMileI 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.71On the client it reads, using IPCONFIG : fe80::20f:b0ff:fe40:ca8f%5On the online convertor I other data ?Online ConvertorThis 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:0047So there seems to be different type of notations going round ?Which makes it more confusing. Regardsptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
JRSmile Posted April 23, 2009 Author Posted April 23, 2009 there is just one standart definded in http://tools.ietf.org/html/rfc4291#section-2.5.5the 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:-)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now