Jump to content

[TCPListen] Get connected IP Address?


Recommended Posts

Still working on my terminal program, and a thought came to me. I've created a TCP server and something connects to it, how do I find out the IP address of what has connected to it? There are no functions that I can find that give me any information about the connected socket. I searched the forum but didn't find anything.

Link to comment
Share on other sites

Func _TCP_Server_ClientIP($hSocket)
    Local $pSocketAddress, $aReturn
    $pSocketAddress = DllStructCreate("short;ushort;uint;char[8]")
    $aReturn = DllCall("ws2_32.dll", "int", "getpeername", "int", $hSocket, "ptr", DllStructGetPtr($pSocketAddress), "int*", DllStructGetSize($pSocketAddress))
    If @error Or $aReturn[0] <> 0 Then Return $hSocket
    $aReturn = DllCall("ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($pSocketAddress, 3))
    If @error Then Return $hSocket
    $pSocketAddress = 0
    Return $aReturn[0]
EndFunc ;==>_TCP_Server_ClientIP

Edited by dragan
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...