Jump to content
Sign in to follow this  
clonetrooper9494

TCP - Getting the IP of a client computer

Recommended Posts

clonetrooper9494

I can't seem to find a way to get the IP of one of the connections returned by TCPAccept(). I can't seem to find a way using any of AutoIts functions... I know there must be a DLL out there, but I don't know how.

Share this post


Link to post
Share on other sites
CodyBarrett

from TCPRecv in the helpfile

Func SocketToIP($SHOCKET)
    Local $sockaddr, $aRet
    
    $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc   ;==>SocketToIP

Share this post


Link to post
Share on other sites
omiden

Wow nice, saving this

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  

×