Jump to content

TCP-Listener


Go to solution Solved by jusb3,

Recommended Posts

I have tried to do a TCP listener, to track some traffic from certain address. I have tried this test-script:

TCPStartup()
$ip = "195.143.118.113"
$port = "4217"
Global $TCPL = TCPListen($ip, $port)

Do
    $TCPA = TCPAccept($TCPL)
Until $TCPA <> -1

Do
    Global $TCPR = TCPRecv($TCPA, 9999999)
Until $TCPR <> ""
MsgBox(0, "Data", $TCPR)

There certinly is traffic, but the listener doesn't respond, is there something wrong with my script?

Link to comment
Share on other sites

I'm pretty certain TCP traffic generally only sends data to one process, meaning with this native function you cannot intercept traffic meant for another application (pretty certain).

Try to explain a little more about what you're trying to accomplish.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

be helpful then if you posted your server script.

Or maybe this is the server script in which case post the client script.

Sorry for my late answer. The server is online, not hosted by me. I'm just connecting to it. Here is the code I have now:

TCPStartup()
            $ip = "195.143.118.113"
            $port = "4217"
            Global $tcp = TCPConnect($ip, $port)
            TCPSend($tcp, _HexToString("3C706F6C6963792D66696C652D726571756573742F3E00") & @CRLF& @CRLF)
            TCPCloseSocket($tcp)
            Global $tcp = TCPConnect($ip, $port)
            TCPSend($tcp, '{"type":"conn","data":{"cmd":"hello"}}' & @CRLF& @CRLF)
            Global $TCPL = TCPListen($ip, $port)
            Do
                Global $TCPA = TCPAccept($TCPL)
            Until $TCPA <> -1
            Do
                Global $TCPR = TCPRecv($TCPA, 1024)
            Until $TCPR <> ""
            MsgBox(0, "Data", $TCPR)

When I run this script I get right response from server, but the listener part still does not react anyway.

Link to comment
Share on other sites

This appears to be for a game. Suggest that you read the forum rules, which are located at the bottom right of each page.

Okay, sorry missed that one. I would still like to know in general how to listen TCP traffic

Link to comment
Share on other sites

try this 

TCPStartup()
$ip = "195.143.118.113"
$port = "4217"
Global $TCPL = TCPListen($ip, $port)

while 1
$TCPA = TCPAccept($TCPL)
$TCPR = TCPRecv($TCPA, 9999999)
if $TCPR <> "" then MsgBox(0, "Data", $TCPR)
wend

if you need a good tcp TUT see this link:

When I use TCPListen, should I use local or remote address? Right now I'm using remote address. And if I have to use local, how can I determine the right port?

Edited by jusb3
Link to comment
Share on other sites

When I use TCPListen, should I use local or remote address? Right now I'm using remote address. And if I have to use local, how can I determine the right port?

you want your script to listen for the device ip

you could use @ipadress if you are on local network

if you are using the internet you must check you pc ip then listen to it

note: when using internet tcp you must be port forwarded

and if you are a noob with tcp stuff i advice u to try first on 2 local PCs or virtual machine then make it through internet 

Link to comment
Share on other sites

Does it make any difference if I'm client or server, because I'm the client, and when I connect to the server, the whole sever-client converstion happens trough single socket, so all I would have to do is get the port at the point I connect and use that port for the rest of the session. I live in apartment, and cannot access the router, so I can't use port forwarding?

Edited by jusb3
Link to comment
Share on other sites

Does it make any difference if I'm client or server, because I'm the client, and when I connect to the server, the whole sever-client converstion happens trough single socket, so all I would have to do is get the port at the point I connect and use that port for the rest of the session. I live in apartment, and cannot access the router, so I can't use port forwarding?

 

i cant get your idea ,the part before " so I can't use port forwarding?" is another question or is description of the situation that wont let u port forward ?

anyway you can port forward without physical access to the router this site will guide you how 

http://portforward.com/

to check if you are port forwarder use canyouseeme.org

Link to comment
Share on other sites

  • Solution

EDIT: I have been able to solve my problem: I had to skip the TCPListen and TCPAccept, and use TCPRecv directly on $tcp, because TCPListen seems to open new connection. Hope this is useful for someone else too.

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