Proxy repeater

« Older   Newer »
  Share  
xdmisterx
CAT_IMG Posted on 8/2/2010, 16:04     +1   -1




Ho fatto questo semplice "proxy server" per programmi in autoit. Non so a cosa potrebbe servire, ma non si sa mai ;D.
Vi posto tre codici: il client e il server(per fare l'esempio di funzionamento), e il proxy repeater vero e proprio(creato per funzionare esclusivamente con il client e il server allegati, ma è il concetto che è fondamentalmente quello :)):
SPOILER (click to view)
Client:
CODICE
;client
TCPStartup()

$ip=InputBox("","Ip del repeater:","","",50,50)
If $ip="" Then Exit

$socket=TCPConnect($ip,9090)
If $socket=-1 Then Exit

While 1
       $recv=TCPRecv($socket,2048)
       If $recv <> "" Then
               If StringInStr($recv,"xCONNx",1) Then
                       $ip2=InputBox("","Ip destinatario:","","",50,50)
                       If $ip2="" Then Exit
                       TCPSend($socket,"xIPx"& $ip2)
               EndIf
               
               If StringInStr($recv,"xOKx",1) Then
                       ExitLoop
               EndIf
               
               If StringInStr($recv,"xFAILEDx",1) Then
                       MsgBox(16,"","Errore nel repeater.",4)
                       Exit
               EndIf
       EndIf
WEnd

While 1
       $msg=InputBox("","Messaggio:","","",50,50)
       If $msg <> "" Then
               TCPSend($socket,$msg)
       Else
               TCPSend($socket,"xEXITx")
               Exit
       EndIf
WEnd


Server:
CODICE
;server
TCPStartup()

$listen=TCPListen(@IPAddress1,9090)
Do
       $socket=TCPAccept($listen)
Until $socket > -1

While 1
       $recv=TCPRecv($socket,2048)
       If $recv <> "" Then
               If StringInStr($recv,"xEXITx",1) Then
                       Exit
               Else
                       MsgBox(0,@IPAddress1,$recv,3)
               EndIf
       EndIf
WEnd


Proxy repeater:
CODICE
;repeater
TCPStartup()

Dim $socket[2]
$con=False

$listen=TCPListen(@IPAddress1,9090)
Do
       $socket[0]=TCPAccept($listen)
Until $socket[0] > -1

TCPSend($socket[0],"xCONNx")

While 1
       $recv=TCPRecv($socket[0],2048)
       
       If $recv <> "" Then
               If StringInStr($recv,"xIPx",1) Then
                       If $con=False Then
                               $ip=StringReplace($recv,"xIPx","")
                               $socket[1]=TCPConnect($ip,9090)
                               If $socket[1]=-1 Then
                                       TCPSend($socket[0],"xFAILEDx")
                                       Exit
                               Else
                                       TCPSend($socket[0],"xOKx")
                                       $con=True
                                       ExitLoop
                               EndIf
                       EndIf
               EndIf
       EndIf
WEnd

While 1
       $recv=TCPRecv($socket[0],2048)
       If $recv <> "" Then
               TCPSend($socket[1],$recv)
       EndIf
       
       $recv1=TCPRecv($socket[1],2048)
       If $recv1 <> "" Then
               TCPSend($socket[0],$recv)
       EndIf
WEnd


Come si può notare, nel repeater, ho utilizzato degli array per i socket.
Il funzionamento è molto semplice: il client si collega al proxy che, a connessione avvenuta, richiede l'indirizzo del server a cui collegarsi. Una volta inviato, il proxy si connette al server. A questo punto il proxy non fa altro che ricevere stringhe(in questo caso) e ritrasmetterle al server di destinazione.
Viceversa, il server può inviare delle stringhe al client passando attraverso il proxy(nel programma non l'ho implementato, ma è semplicissimo, basta modificare il server per l'invio di stringhe).
Adesso che ci penso, potrebbe essere utile nel caso non si può effettuare una connessione diretta con il server, ma bisogna per forza passare per un proxy(magari quello aziendale).
Io l'ho testato con tre computer nella rete locale, ma per esperienza dico che funziona anche in rete esterna(tralasciando eventuali router ;)).
ciao :)
 
Top
Lahace
CAT_IMG Posted on 8/2/2010, 16:25     +1   -1




sarebbe bello se fuonzionasse con i router xD speriamo escano presto le funzioni per la vpn
 
Top
xdmisterx
CAT_IMG Posted on 8/2/2010, 16:52     +1   -1




i router li bypassi facilmente con una reverse connection. tutto dipende da cosa devi fare....
 
Top
2 replies since 8/2/2010, 16:04   99 views
  Share