creando un "proxy"
Publicado: 01 Mar 2011, 22:05
buenas..
estoi intentando crear un programa k sea como un servidor, para conectarse atraves de un navegador cualkiera komo ffox, y lo que este aga sea como intermediar entre la red social tuenti y el cliente... lo ago por k en mi instituto lo tenemos bloqueado, no es ningun tema de malware.
el funcionamiento seria en plan el cliente envia datos a mi server, mi server se los envia a tuenti. tuenti envia datos al server i mi server al cliente.
este es el codigo que llevo, un pokin escaso i basado en un servidor web de Manadar
en principio funciona, pero en la pagina de tuenti me aparece como que mis cookies estan desactivadas.
el codigo:
estoi intentando crear un programa k sea como un servidor, para conectarse atraves de un navegador cualkiera komo ffox, y lo que este aga sea como intermediar entre la red social tuenti y el cliente... lo ago por k en mi instituto lo tenemos bloqueado, no es ningun tema de malware.
el funcionamiento seria en plan el cliente envia datos a mi server, mi server se los envia a tuenti. tuenti envia datos al server i mi server al cliente.
este es el codigo que llevo, un pokin escaso i basado en un servidor web de Manadar
en principio funciona, pero en la pagina de tuenti me aparece como que mis cookies estan desactivadas.
el codigo:
Código: Seleccionar todo
#cs
Resources:
Internet Assigned Number Authority - all Content-Types: http://www.iana.org/assignments/media-types/
World Wide Web Consortium - An overview of the HTTP protocol: http://www.w3.org/Protocols/
Credits:
Manadar for starting on the webserver.
Alek for adding POST and some fixes
Creator for providing the "application/octet-stream" MIME type.
#ce
#include <string.au3>
; // OPTIONS HERE //
Local $sRootDir = @ScriptDir & "\www" ; The absolute path to the root directory of the server.
Local $sIP = "127.0.0.1" ; ip address as defined by AutoIt
Local $iPort = 80 ; the listening port
Local $sServerAddress = "http://" & $sIP & ":" & $iPort & "/"
Local $iMaxUsers = 15 ; Maximum number of users who can simultaneously get/post
Local $sServerName = "ManadarX/1.1 (" & @OSVersion & ") AutoIt " & @AutoItVersion
; // END OF OPTIONS //
Local $aSocket[$iMaxUsers] ; Creates an array to store all the possible users
Local $sBuffer[$iMaxUsers] ; All these users have buffers when sending/receiving, so we need a place to store those
For $x = 0 to UBound($aSocket)-1 ; Fills the entire socket array with -1 integers, so that the server knows they are empty.
$aSocket[$x] = -1
Next
TCPStartup() ; AutoIt needs to initialize the TCP functions
$iMainSocket = TCPListen($sIP,$iPort) ;create main listening socket
If @error Then ; if you fail creating a socket, exit the application
MsgBox(0x20, "AutoIt Webserver", "Unable to create a socket on port " & $iPort & ".") ; notifies the user that the HTTP server will not run
Exit ; if your server is part of a GUI that has nothing to do with the server, you'll need to remove the Exit keyword and notify the user that the HTTP server will not work.
EndIf
ConsoleWrite( "Server created on " & $sServerAddress & @CRLF) ; If you're in SciTE,
While 1
$iNewSocket = TCPAccept($iMainSocket) ; Tries to accept incoming connections
If $iNewSocket >= 0 Then ; Verifies that there actually is an incoming connection
For $x = 0 to UBound($aSocket)-1 ; Attempts to store the incoming connection
If $aSocket[$x] = -1 Then
$aSocket[$x] = $iNewSocket ;store the new socket
ExitLoop
EndIf
Next
EndIf
For $x = 0 to UBound($aSocket)-1 ; A big loop to receive data from everyone connected
If $aSocket[$x] = -1 Then ContinueLoop ; if the socket is empty, it will continue to the next iteration, doing nothing
$sNewData = TCPRecv($aSocket[$x],1024) ; Receives a whole lot of data if possible
If @error Then ; Client has disconnected
$aSocket[$x] = -1 ; Socket is freed so that a new user may join
ContinueLoop ; Go to the next iteration of the loop, not really needed but looks oh so good
ElseIf $sNewData Then ; data received
$host = _StringBetween($sNewData,"Host: ",@CRLF)
;If StringInStr($sNewData,"127.0.0.1") Then
;$sNewData = StringReplace($sNewData,"127.0.0.1","www.tuenti.com")
$host = "www.tuenti.com"
;EndIf
c_w($sNewData)
$hSocket = TCPConnect(TCPNameToIP($host),80)
SendData($hSocket, $sNewData)
MsgBox(0,"","1")
Local $result, $receive
Do
$result = TCPRecv($hSocket,3024)
Until $result <> ""
Do
$receive = TCPRecv($hSocket,3024) ; loop ke no para de recivir asta k no falle la conexion o se reciva </html>
$result &= $receive
Until @error
c_w(BinaryToString($result))
MsgBox(0,"","2.5")
SendData($aSocket[$x], BinaryToString($result))
MsgBox(0,"","2")
EndIf
$sBuffer[$x] = "" ; clears the buffer because we just used to buffer and did some actions based on them
$aSocket[$x] = -1 ; the socket is automatically closed so we reset the socket so that we may accept new clients
Next
Sleep(10)
WEnd
Func c_w($dat)
ConsoleWrite($dat&@CRLF)
EndFunc
Func SendData($hSocket, $bData)
For $i = 1 To StringLen($bData)
TCPSend($hSocket,StringMid($bData,$i,1))
Next
EndFunc