Sign in to follow this  
Followers 0
E1M1

Need help with proxy (Illustration added)

9 posts in this topic

#1 ·  Posted (edited)

Hello, I am trying to make simple proxy, but how do I listen server responce? I see packet sent by client, and I send that packet to server, but how do I listen server's responce and how do i send it to client? I have tried to copy this script and cnanged 127.0.0.1 to @ipAddress1 so I had 2 standalone scripts, but thatway it didn't work. Any other ideas how to listen server responce and send it to client? if you look at how I forward packet to server, what do you say: Is this ok?

Here's little illustration :mellow:

Posted Image

#include <GUIConstantsEx.au3>

;~ Opt('MustDeclareVars', 1)

;==============================================
;==============================================
;SERVER!! Start Me First !!!!!!!!!!!!!!!
;==============================================
;==============================================

Example()

Func Example()
    ; Set Some reusable info
    ; Set your Public IP address (@IPAddress1) here.
;   Local $szServerPC = @ComputerName
;   Local $szIPADDRESS = TCPNameToIP($szServerPC)
    Local $szIPADDRESS = "127.0.0.1";localip
    Local $nPORT = 22;tcp port for login and chatlobby
    local $remoteszIPADDRESS = "213.248.106.204";Server
    Local $MainSocket, $GOOEY, $edit, $ConnectedSocket, $szIP_Accepted
    Local $msg, $recv

    ; Start The TCP Services
    ;==============================================
    TCPStartup()

    ; Create a Listening "SOCKET".
    ;   Using your IP Address and Port 33891.
    ;==============================================
    $MainSocket = TCPListen($szIPADDRESS, $nPORT)

    ; If the Socket creation fails, exit.
    If $MainSocket = -1 Then Exit


    ; Create a GUI for messages
    ;==============================================
    $GOOEY = GUICreate("proxy (IP: " & $szIPADDRESS & ")", 800, 200)
    $edit = GUICtrlCreateEdit("", 10, 10, 780, 180)
    GUISetState()


    ; Initialize a variable to represent a connection
    ;==============================================
    $ConnectedSocket = -1


    ;Wait for and Accept a connection
    ;==============================================
    Do
        $ConnectedSocket = TCPAccept($MainSocket)
    Until $ConnectedSocket <> -1
    $remoteConnectedSocket = TCPConnect($remoteszIPADDRESS, $nPORT)
;~  MsgBox(0,0,$remoteConnectedSocket)


    ; Get IP of client connecting
    $szIP_Accepted = SocketToIP($ConnectedSocket)

    ; GUI Message Loop
    ;==============================================
    While 1
        $msg = GUIGetMsg()

        ; GUI Closed
        ;--------------------
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop

        ; Try to receive (up to) 2048 bytes
        ;----------------------------------------------------------------
        $recv = TCPRecv($ConnectedSocket, 2048)

        ; If the receive failed with @error then the socket has disconnected
        ;----------------------------------------------------------------
        If @error Then ExitLoop

        ; Update the edit control with what we have received
        ;----------------------------------------------------------------
        If $recv <> "" Then
        GUICtrlSetData($edit, $szIP_Accepted & " > " & $recv & @CRLF & GUICtrlRead($edit))
        ConsoleWrite(TCPSend($remoteConnectedSocket,$recv)&@CRLF);debug
        EndIf
    WEnd


    If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)

    TCPShutdown()
EndFunc   ;==>Example


; 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), "int*", 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
Edited by E1M1

edited

Share this post


Link to post
Share on other sites



bump


edited

Share this post


Link to post
Share on other sites

mmmm removed 3 bumps and bump it again...

Wondering how long you continue this.

Just wanted to clean it abit.

how long I continue this?

Until I get some help

What's the bump rule for this site? 24 hour?


edited

Share this post


Link to post
Share on other sites

What's the bump rule for this site? 24 hour?

Correct, but there will be a time that it will be closed.

I would think that after 4 bumps without a single reply that there is a slight chance that the question "isn't clear"/"too complex"/"too much work before anyone can test"/"whatever else" for anybody to touch it, it would dawn on you that you need to do some work first yourself.... or does this really sound ridiculous?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Rght. I have done what I could,now I just need little hink about how to go on with it. Is my question unclear or too complex or what I did wrong with tis topic??

I know my english isn't always clear but i usually get some hints/help.

Do you have any idea about what I could try?

Edited by E1M1

edited

Share this post


Link to post
Share on other sites

bump


edited

Share this post


Link to post
Share on other sites

Is it just my feeling or are there increasingly more people having problems and less experienced people willing to help them here? I have seen several interesting questions unanswered just today...

I have some experience with UDP, but not TCP. I plan to try something with TCP in the near future though...

Share this post


Link to post
Share on other sites

Look this:

http://www.autoitscript.com/forum/index.php?showtopic=44138&st=0&p=328722&hl=proxy&fromsearch=1&#entry328722

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