Sign in to follow this  
Followers 0
E1M1

[Solved] How to convert string ip to int

4 posts in this topic

#1 ·  Posted (edited)

From tcp server example I found code converts Int to string

$aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", 2130706433)
  If Not @error Then $aRet = $aRet[0]

But how i can convert string IP to int again?

Solution: inet_addr

Edited by E1M1

edited

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

thanks, I googled for it but didn't find. or actually didn't know what to look


edited

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0