Jump to content

TCP traffic monitoring


Recommended Posts

First I would like to say that I am not making a client/server chat or anything like that. All I want to do is log all raw data that comes in and out of a port of my choice. Can anyone please show me a sample script to do something like this?

This is what I got so far, but it doesn't work:

#NoTrayIcon
#include <File.au3>

TCPStartup()
$MainSocket = TCPListen(@IPAddress1, 6112)
If $MainSocket == -1 Then
    MsgBox(0, "TCP Error", "Error Listening on TCP" & @CRLF & "@error = " & @error)
    Exit
EndIf
While 1
    $Socket = TCPAccept($MainSocket)
    If $Socket >= 0 Then
        $recv = ''
        While $recv = ''
            $recv = TCPRecv($Socket, 10000)
            If @error Then ExitLoop
        WEnd
        _FileWriteLog(@ScriptDir & "\my.log", $recv)        
        $recv = ''
    EndIf
WEnd
Link to comment
Share on other sites

First I would like to say that I am not making a client/server chat or anything like that. All I want to do is log all raw data that comes in and out of a port of my choice. Can anyone please show me a sample script to do something like this?

This is what I got so far, but it doesn't work:

#NoTrayIcon
#include <File.au3>

TCPStartup()
$MainSocket = TCPListen(@IPAddress1, 6112)
If $MainSocket == -1 Then
    MsgBox(0, "TCP Error", "Error Listening on TCP" & @CRLF & "@error = " & @error)
    Exit
EndIf
While 1
    $Socket = TCPAccept($MainSocket)
    If $Socket >= 0 Then
        $recv = ''
        While $recv = ''
            $recv = TCPRecv($Socket, 10000)
            If @error Then ExitLoop
        WEnd
        _FileWriteLog(@ScriptDir & "\my.log", $recv)        
        $recv = ''
    EndIf
WEnd

Looks ok to me. Are you sure something is being sent to that port?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...