Moin,
ich möchte ein kleines Programm zur Umrechnung von IP-Adressen erstellen. Meine Anfänge sind soweit auch in Ordnung, aber
1. kriege ich es nicht hin, eine IP in's Binärformat umzuwandeln
2. hat das Ganze starken optimierungsbedarf
Func calcIPv4()
Local $ip
Local $1, $2, $3, $4, $5, $6, $7, $8
Local $block1, $block2, $block3, $block4
Local $field = GUICtrlRead($Input3)
$1 = StringMid($field, 1, 1) * 128
$2 = StringMid($field, 2, 1) * 64
$3 = StringMid($field, 3, 1) * 32
$4 = StringMid($field, 4, 1) * 16
$5 = StringMid($field, 5, 1) * 8
$6 = StringMid($field, 6, 1) * 4
$7 = StringMid($field, 7, 1) * 2
$8 = StringMid($field, 8, 1) * 1
$block1 = $1 + $2 + $3 + $4 + $5 + $6 + $7 + $8
[/autoit][autoit][/autoit][autoit]$1 = StringMid($field, 9, 1) * 128
$2 = StringMid($field, 10, 1) * 64
$3 = StringMid($field, 11, 1) * 32
$4 = StringMid($field, 12, 1) * 16
$5 = StringMid($field, 13, 1) * 8
$6 = StringMid($field, 14, 1) * 4
$7 = StringMid($field, 15, 1) * 2
$8 = StringMid($field, 16, 1) * 1
$block2 = $1 + $2 + $3 + $4 + $5 + $6 + $7 + $8
[/autoit][autoit][/autoit][autoit]$1 = StringMid($field, 17, 1) * 128
$2 = StringMid($field, 18, 1) * 64
$3 = StringMid($field, 19, 1) * 32
$4 = StringMid($field, 20, 1) * 16
$5 = StringMid($field, 21, 1) * 8
$6 = StringMid($field, 22, 1) * 4
$7 = StringMid($field, 23, 1) * 2
$8 = StringMid($field, 24, 1) * 1
$block3 = $1 + $2 + $3 + $4 + $5 + $6 + $7 + $8
[/autoit][autoit][/autoit][autoit]$1 = StringMid($field, 25, 1) * 128
$2 = StringMid($field, 26, 1) * 64
$3 = StringMid($field, 27, 1) * 32
$4 = StringMid($field, 28, 1) * 16
$5 = StringMid($field, 29, 1) * 8
$6 = StringMid($field, 30, 1) * 4
$7 = StringMid($field, 31, 1) * 2
$8 = StringMid($field, 32, 1) * 1
$block4 = $1 + $2 + $3 + $4 + $5 + $6 + $7 + $8
[/autoit][autoit][/autoit][autoit]$ip = $block1 & "." & $block2 & "." & $block3 & "." & $block4
[/autoit][autoit][/autoit][autoit]GUICtrlSetData($Input4, $ip)
EndFunc
Das ist die Funktion zum Umrechnen von Binärcode in eine IP. Das funktioniert auch soweit. Frage dazu: Geht das einfacher?
[autoit]Func calcBinary()
Local $field = GUICtrlRead($Input1)
Local $binparts
$parts = StringSplit($field, ".")
[/autoit][autoit][/autoit][autoit]For $k = 1 To $parts[0]
$bin = ''
For $i = 0 To 7
If IsInt($parts[$k]) Then
$bin &= 0
Else
$bin &= 1
EndIf
$parts[$k] = Floor($parts[$k]) / 2
Next
$binparts &= $bin
Next
GUICtrlSetData($Input2, $binparts)
EndFunc
Das ist die bisherige Funktion zum Umwandeln einer IP in Binärcode. Das funktioniert vom Grundprinzip her, jedoch erhalte ich falsche Ergebnisse. Frage dazu: Was mache ich falsch?
Wäre klasse, wenn jemand eine Idee dazu hat.