Sign in to follow this  
Followers 0
Zaxon

Getting Connected IP and Port info

9 posts in this topic

I'm trying to get the IP address, port #, and possibly even do a lookup to resolve the name of the remote peer that you're connected with via TCP/IP (using the inbuild AutoIt TCP connection commands). This needs to work on both the client and server sides. I can do this with PERL quite easily, but I'm trying do replicate that functionality with AutoIt.

The SocketToIP() function given in the AutoIt help doesn't seem to work, even after I modify it because int_ptr is now a deprecated type. In addition, it never gave the port #. I've combed the forums for this info and read countless posts, but haven't seen mention of how to get this basic info about your connection.

Share this post


Link to post
Share on other sites



What about :

They're external commands. Given that your AutoIt script has the TCP connection, you'd think you'd be able to interrogate that connection directly from within AutoIt or at the least via a DLL call.

Share this post


Link to post
Share on other sites

@Zaxon

OK it"s external but what is the difference if you use an external DLLCall or an external EXE

both return the information :

#include <Constants.au3>

$sCommand= Run("netstat -a", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StdoutRead($sCommand)
    If @error Then ExitLoop
    ConsoleWrite( "STDOUT read:" & $line & @LF)
Wend

While 1
    $line = StderrRead($sCommand)
    If @error Then ExitLoop
    ConsoleWrite( "STDERR read:" & $line & @LF) 
Wend

regards

ptrex

Share this post


Link to post
Share on other sites

OK it"s external but what is the difference if you use an external DLLCall or an external EXE

both return the information

External programs start a whole new process - an expensive operation in windows. Certainly in compiled or linked languages, you don't have this overhead with .dlls. I'm not sure how DllCall is treated in AutoIt, whether the autoit.exe program links to the dll directly from the process, or whether a new process entirely is launched.

With the commands you've given, and thank you for what you've provided so far :P , netstat -a gives a list of every connection on your system. I could string parse that to find the details I need I presume, but that's a far cry from what I'm expecting to do. In PERL, I can interrogate the connection object of my current connection directly and it will happy tell me the IP and port of my current connection. No need for external commands or parsing down a couple of pages of netstat output to find the one thing I'm interested in.

The SocketToIP($SHOCKET) used to work (I'm assuming). I've changed one of the types from int_ptr to int, as directed by the output I received, but I'm currently just get "0" return. Plus, a port was never returned, though I'm sure it's just another dll call away.

Share this post


Link to post
Share on other sites

I've changed one of the types from int_ptr to int

Did you try and change int_ptr to int*? (The * is the new way to define pointers).

Just guessing here.

Share this post


Link to post
Share on other sites

Did you try and change int_ptr to int*? (The * is the new way to define pointers).

Just guessing here.

Good guess - it worked!

Now, do we know the dll calls to resolve the remote port number?

Share this post


Link to post
Share on other sites

This is still actual for me. Could any body help?

Something is wrong here:

Func SocketToPort($SHOCKET)
    Local $sockaddr, $aRet

    $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    $aRet = DllCall("Ws2_32.dll", "int", "getnameinfo", "int", $SHOCKET, _
            "int", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "int", "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

Please,help somebody. I need it very very much!

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