acmecd Posted December 28, 2013 Posted December 28, 2013 There is very nice well know script to get Socket To IP, that’s work good. But, I need get with connected IP also remote port, (IP:Port) there are any ideas how to upgrade script. ; Function to return IP Address from a connected socket. ;---------------------------------------------------------------------- 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
SlowCoder74 Posted June 13, 2014 Posted June 13, 2014 I'm going to go ahead and bump this, as it is exactly the same question I was going to ask. I'd like to know how I can retrieve the client's port.
funkey Posted June 14, 2014 Posted June 14, 2014 Give me just a bit more information what exactly you have and what exactly you want to achieve. For example you have opened a connection to a server and want to know what local port is opened or what? With a little bit more details I'm sure I can help you (if I have time ). Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning.
SlowCoder74 Posted June 17, 2014 Posted June 17, 2014 Yes, that is correct. I would like to know which local port is in use by the connected socket.
funkey Posted June 18, 2014 Posted June 18, 2014 I wrote this function a few years ago: Func _Ws2_GetLocalPort($iSocket) ;funkey Local $hDLL = DllOpen("Ws2_32.dll") Local $tagIN_ADDR = "ulong S_addr;" Local $tagSOCKADDR_IN = "short sin_family;ushort sin_port;ptr sin_addr;char sin_zero[8];" Local $tIn_Addr = DllStructCreate($tagIN_ADDR) Local $tName = DllStructCreate($tagSOCKADDR_IN) DllStructSetData($tName, "sin_addr", DllStructGetPtr($tIn_Addr)) Local $aRes = DllCall($hDLL, "int", "getsockname", "uint", $iSocket, "struct*", $tName, "int*", 512) Local $aRes2 = DllCall($hDLL, "ushort", "ntohs", "ushort", DllStructGetData($tName, 2)) DllClose($hDLL) Return $aRes2[0] EndFunc Hope this is what you want. SlowCoder74 1 Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning.
SlowCoder74 Posted June 19, 2014 Posted June 19, 2014 Funkey, that was exactly what I was looking for. Thank you.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now