Alan72104

ipv6 boom

Feb 11th, 2021 (edited)
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.66 KB | None | 0 0
  1. Func boom($str)
  2.     If StringLeft($str, 1) = ":" Then
  3.         $str = StringTrimLeft($str, 1)
  4.     EndIf
  5.     If StringRight($str, 1) = ":" Then
  6.         $str = StringTrimRight($str, 1)
  7.     EndIf
  8.     Local $aSplit = StringSplit($str, ":", $STR_NOCOUNT)
  9.     Local $rtn = ""
  10.     For $i = 0 To UBound($aSplit) - 1  ; Loop through all the elements
  11.         If Not $aSplit[$i] = "" Then  ; If not a shortened element
  12.             $rtn &= StringPadLeft($aSplit[$i], 4, "0")
  13.         Else  ; It is a shortened element
  14.             For $j = 0 To 8 - UBound($aSplit)  ; Append 0000 for yes times
  15.                 $rtn &= "0000"
  16.                 If $j < 8 - UBound($aSplit) Then  ; Append : if not last iteration
  17.                     $rtn &= ":"
  18.                 EndIf
  19.             Next
  20.         EndIf
  21.         If $i < UBound($aSplit) - 1 Then  ; Append : if not last iteration
  22.             $rtn &= ":"
  23.         EndIf
  24.     Next
  25.     Return $rtn
  26. EndFunc
  27.  
  28. Func StringPadLeft($str, $digit, $pad)
  29.     Local $rtn = ""
  30.     For $i = 1 To $digit - StringLen($str)
  31.         $rtn &= $pad
  32.     Next
  33.     $rtn &= $str
  34.     Return $rtn
  35. EndFunc
  36.  
  37. ConsoleWrite(boom("1234:0:2d::") & @CRLF)
  38. ConsoleWrite(boom("::123:12:0:bc") & @CRLF)
  39. ConsoleWrite(boom("::") & @CRLF)
  40. ConsoleWrite(boom(":") & @CRLF)
  41. ConsoleWrite(boom("2::1") & @CRLF)
  42. ConsoleWrite(boom("::1") & @CRLF)
  43. ConsoleWrite(boom("1234:0000:002d:0000:0000:0000:0000:0000") & @CRLF)
  44. ConsoleWrite(boom("b3c::2:0:10:11") & @CRLF)
  45. ConsoleWrite(boom("2001:db8:0:0:1:0:0:1") & @CRLF)
  46. ConsoleWrite(boom("2001:0db8:0:0:1:0:0:1") & @CRLF)
  47. ConsoleWrite(boom("2001:db8::1:0:0:1") & @CRLF)
  48. ConsoleWrite(boom("2001:db8::0:1:0:0:1") & @CRLF)
  49. ConsoleWrite(boom("2001:0db8::1:0:0:1") & @CRLF)
  50. ConsoleWrite(boom("2001:db8:0:0:1::1") & @CRLF)
  51. ConsoleWrite(boom("2001:db8:0000:0:1::1") & @CRLF)
  52. ConsoleWrite(boom("2001:DB8:0:0:1::1") & @CRLF)
Add Comment
Please, Sign In to add comment