Jump to content

[Solved] How to convert string ip to int


E1M1
 Share

Recommended Posts

MSDN is your friend :D, search for inet_ntoa, read documentation and look for similar functions...

$aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", 2130706433)
If Not @error Then $aRet = $aRet[0]
ConsoleWrite($aRet & @crlf)
$aRet = DllCall("Ws2_32.dll", "long", "inet_addr", "str", $aRet & chr(0))
If Not @error Then $aRet = $aRet[0]
ConsoleWrite($aRet & @crlf)

Edit: To be correct, return is long on not int.

Edited by KaFu
Link to comment
Share on other sites

I would go with more natural solution any time over that calls considering the language we use:

$sIP = "255.255.255.255"
 
; Verify reversibleness
ConsoleWrite(_IPToString(_StringToIP($sIP)) & @CRLF)
 
Func _IPToString($iIP)
    Return Number(BinaryMid($iIP, 1, 1)) & "." & Number(BinaryMid($iIP, 2, 1)) & "." & Number(BinaryMid($iIP, 3, 1)) & "." & Number(BinaryMid($iIP, 4, 1))
EndFunc
 
Func _StringToIP($sIP)
    Local $aIP = StringSplit($sIP, ".")
    ReDim $aIP[5]
    Return Dec(Hex($aIP[4], 2) & Hex($aIP[3], 2) & Hex($aIP[2], 2) & Hex($aIP[1], 2))
EndFunc

...Ssspeeeedd

Edited by trancexx

♡♡♡

.

eMyvnE

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...