Jump to content

How can i recive from a open socket?


Recommended Posts

Okey, I think i'm doing what i want half way works.

I can't send data well i don't think it sends but don't recive.

You see the option to connnect to the socket id witch would already be connected through a third party.

But when you do that i can't seam to send the data to the program this black it and catches.

So it will need to send the recived data to the server after if reciveds it.

$socket = 0
$MainSocket = 0
#include <String.au3>
#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=c:\users\kcd\documents\newtcp.kxf
$Form1_1_1 = GUICreate("AForm1", 1209, 809, 0, 0)
$recivedataHEX = GUICtrlCreateEdit("", 0, 16, 353, 121)
$datatosendHEX = GUICtrlCreateEdit("", 0, 296, 353, 129)
$Label1 = GUICtrlCreateLabel("Recived Data", 0, 0, 70, 17)
$Data = GUICtrlCreateLabel("Data To Send", 0, 272, 71, 17)
$Obj1 = ObjCreate("Shell.Explorer.2")
$Obj1_ctrl = GUICtrlCreateObj($Obj1, 352, 0, 856, 808)
$Send = GUICtrlCreateButton("Send Text", 0, 568, 355, 25, 0)
$ip = GUICtrlCreateInput("127.0.0.1", 40, 600, 121, 21)
$a = GUICtrlCreateLabel("Ip", 24, 608, 13, 17)
$b = GUICtrlCreateLabel("Port", 168, 608, 23, 17)
$port = GUICtrlCreateInput("8181", 192, 600, 121, 21)
$sockeid = GUICtrlCreateInput("", 88, 624, 49, 21)
$c = GUICtrlCreateLabel("Socket Id", 40, 632, 50, 17)
$Connect = GUICtrlCreateButton("Connect", 240, 624, 75, 25, 0)
$ReadId = GUICtrlCreateButton("Read Id", 160, 624, 75, 25, 0)
$Label2 = GUICtrlCreateLabel("Ip", 24, 720, 13, 17)
$listenip = GUICtrlCreateInput("127.0.0.1", 40, 712, 121, 21)
$Label3 = GUICtrlCreateLabel("Port", 168, 720, 23, 17)
$listenport = GUICtrlCreateInput("8181", 192, 712, 121, 21)
$Label4 = GUICtrlCreateLabel("Socket Id", 40, 744, 50, 17)
$socketid = GUICtrlCreateInput("", 88, 736, 49, 21)
$idlisten = GUICtrlCreateButton("Listen to id", 160, 736, 75, 25, 0)
$Listen = GUICtrlCreateButton("Listen", 240, 736, 75, 25, 0)
$stopconn = GUICtrlCreateButton("Stop Connection", 160, 656, 155, 25, 0)
$stoplisten = GUICtrlCreateButton("Stop Listening", 160, 768, 155, 25, 0)
$recivedata = GUICtrlCreateEdit("", 0, 136, 353, 121)
$datatosend = GUICtrlCreateEdit("", 0, 448, 353, 121)
$sendhex = GUICtrlCreateButton("Send Hex", 0, 424, 355, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


$Obj1.navigate ("")

TCPStartup()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Send
            $hexdata = _StringToHex(GUICtrlRead($datatosend))
            $normdata = GUICtrlRead($datatosend)
            TCPSend($socket, $hexdata)
            GUICtrlSetData($datatosendHEX, $hexdata)
        Case $sendhex
            $hexdata = GUICtrlRead($datatosendHEX)
            $normdata = _HexToString($hexdata)
            TCPSend($socket, $hexdata)
            GUICtrlSetData($datatosend, $normdata)
        Case $Connect
            $sip = GUICtrlRead($ip)
            $sport = GUICtrlRead($port)
            $socket = TCPConnect($sip, $sport)
            GUICtrlSetData($sockeid, $socket)
            If @error Then
                MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)
            EndIf
        Case $ReadId
            $socket = GUICtrlRead($sockeid)
        Case $idlisten
            $MainSocket = GUICtrlRead($socketid)
            TCPAccept($MainSocket)
            If @error Then
                MsgBox(4112, "Error", "TCPlisten failed with WSA error: " & @error)
            EndIf
        Case $Listen
            $lip = GUICtrlRead($listenip)
            $lport = GUICtrlRead($listenport)
            $MainSocket = TCPListen($lip, $lport, 100)
            If $MainSocket = -1 Then
                MsgBox(0, "Error conn...", "Error listening.")
                Exit
            EndIf
            GUICtrlSetData($socketid, $socket)
            TCPAccept($MainSocket)
            If @error Then
                MsgBox(4112, "Error", "TCPlisten failed with WSA error: " & @error)
            EndIf
        Case $stopconn
            TCPCloseSocket($socket)
            GUICtrlSetData($recivedataHEX, "")
            GUICtrlSetData($recivedata, "")
;~          TCPShutdown()
        Case $stoplisten
            TCPCloseSocket($MainSocket)
            GUICtrlSetData($recivedataHEX, "")
            GUICtrlSetData($recivedata, "")
;~          TCPShutdown()
    EndSwitch
    
    $datarec = TCPRecv($socket, 2048)
    If $datarec <> "" Then
        GUICtrlSetData($recivedataHEX, "Socket: " & $datarec & @CRLF, 0)
        $datarec1 = _HexToString(StringTrimLeft($datarec, 2))
        GUICtrlSetData($recivedata, "Socket: " & $datarec1 & @CRLF, 0)
    EndIf
    
    $datarec2 = TCPRecv($MainSocket, 2048)
    If $datarec2 <> "" Then
        GUICtrlSetData($recivedataHEX, "MainSocket: " & $datarec2 & @CRLF, 0)
        $datarec3 = _HexToString(StringTrimLeft($datarec2, 2))
        GUICtrlSetData($recivedata, "MainSocket: " & $datarec3 & @CRLF, 0)
    EndIf
WEnd
TCPShutdown()
Edited by gvus
Link to comment
Share on other sites

This sounds some what complicated. Try moving your thread to the Developer Chat section. Be sure to say your reposting if you cant delete this one or the new one will just contain flame messages..

Link to comment
Share on other sites

gvus, Hard to understand your question... Tell me if im right-

There is a tcp connection running on your computer made by some program (meaning if you type 'netstat -n' at the command prompt, it shows the connection you''re wanting) and you want to use AutoIt to intercept data being sent by the other application through that connection and also use AutoIt to intercept incomming data received through that connection. Is this correct?

Edited by evilertoaster
Link to comment
Share on other sites

$datarec = TCPRecv($socket, 2048)
    If $datarec <> "" Then
        GUICtrlSetData($recivedataHEX, "Socket: " & $datarec & @CRLF, 0)
        $datarec1 = _HexToString(StringTrimLeft($datarec, 2))
        GUICtrlSetData($recivedata, "Socket: " & $datarec1 & @CRLF, 0)
    EndIf

This will do nothing, you need to recieve from your TCPAccept socket.

Link to comment
Share on other sites

You see the option to connnect to the socket id witch would already be connected through a third party.

But when you do that i can't seam to send the data to the program this black it and catches.

if your script did not create the socket you can't read from it, so there is no easy way to "spy" on an existing socket!

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

evilertoaster that is correct

/dev/null

I can intersept but that is just it it stops the data in the script.

ANyways the problem is sending the data to the already open socket on local

Link to comment
Share on other sites

/dev/null

I can intersept but that is just it it stops the data in the script.

we are talking about different things!

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

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...