Jump to content
Sign in to follow this  
MerkurAlex

TCPAccept get ip when the client connects?

Recommended Posts

MerkurAlex

Read the title! Also i cannot have the client send the ip i need to get it when they connect before the client sends anything.


[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Share this post


Link to post
Share on other sites
LarryDalooza

socket2ip... i think

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites
MerkurAlex

Hello Lar i was unable to find that function in the help file or on the forums.

Well actually i found this where the person uses the function but he is not defining it... #113353

Edited by MerkurAlex

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Share this post


Link to post
Share on other sites
Glyph

; 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), "ptr", 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

Under TCPRecv in the helpfile.

Acutally the help file fails.

Edited by Glyph

tolle indicium

Share this post


Link to post
Share on other sites
MerkurAlex

... Brilliant lol thanks.

Actually not brilliant... it returns 0 everytime.

Edited by MerkurAlex

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Share this post


Link to post
Share on other sites
Glyph

... Brilliant lol thanks.

Actually not brilliant... it returns 0 everytime.

Weird, I was getting the same returns on x64.

Do you use x64 or x86?


tolle indicium

Share this post


Link to post
Share on other sites
MerkurAlex

No clue lol i got the laptop from work im pretty sure its x86...


[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Share this post


Link to post
Share on other sites
Kip

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 0
    
    $aReturn = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($pSocketAddress, 3))
    If @error Then Return 0
    
    $pSocketAddress = 0
    
    Return $aReturn[0]
    
EndFunc

Share this post


Link to post
Share on other sites
Glyph

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 0
    
    $aReturn = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($pSocketAddress, 3))
    If @error Then Return 0
    
    $pSocketAddress = 0
    
    Return $aReturn[0]
    
EndFunc
Hah, The helpfile should be fixed. Thank-you for sharing that code with us!

I remember seeing that fix before, but it slipped my mind!

Edited by Glyph

tolle indicium

Share this post


Link to post
Share on other sites
MerkurAlex

Thank you kip!


[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

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  

×