Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <winsock2.h>
- #include <windows.h>
- #include "hexdump.h"
- #define DEFAULT_BUFLEN 8192
- using namespace std;
- int main()
- {
- char localAddress[] = "127.0.0.1";
- int localPort = 443;
- char serverAddress[] = "213.248.126.180";
- int serverPort = 443;
- char fServer[DEFAULT_BUFLEN];
- char fClient[DEFAULT_BUFLEN];
- cout << "PROXY" << endl;
- WSADATA WSAData;
- WSAStartup(MAKEWORD(2,0), &WSAData);
- SOCKET socketClient;
- SOCKADDR_IN c;
- SOCKADDR_IN csin;
- c.sin_addr.s_addr = inet_addr(localAddress);
- c.sin_family = AF_INET;
- c.sin_port = htons(localPort);
- socketClient = socket(AF_INET,SOCK_STREAM,0);
- bind(socketClient, (SOCKADDR *)&c, sizeof(c));
- listen(socketClient, 0);
- cout << "Proxy start listening" << endl;
- cout << "Waiting client..." << endl;
- int sizeof_csin = sizeof(csin);
- if((socketClient = accept(socketClient, (SOCKADDR *)&csin, &sizeof_csin)) != INVALID_SOCKET)
- {
- cout << "Client connected" << endl;
- SOCKET socketServer;
- SOCKADDR_IN s;
- s.sin_addr.s_addr = inet_addr(serverAddress);
- s.sin_family = AF_INET;
- s.sin_port = htons(serverPort);
- socketServer = socket(AF_INET,SOCK_STREAM,0);
- connect(socketServer, (SOCKADDR *)&s, sizeof(s));
- cout << "Proxy connected on server" << endl;
- while(true)
- {
- if(recv(socketServer, fServer, sizeof(fServer), 0) != SOCKET_ERROR)
- {
- cout << "Data from server" << endl;
- send(socketClient, fServer, sizeof(fServer), 0);
- hexdump(fServer, sizeof(fServer));
- Sleep(1000); // Trop rapide si non
- cout << "Data sended to client" << endl;
- }
- if(recv(socketClient, fClient, sizeof(fClient), 0) != SOCKET_ERROR)
- {
- cout << "Data from client" << endl;
- send(socketServer, fClient, sizeof(fClient), 0);
- hexdump(fClient, sizeof(fClient));
- Sleep(1000);
- cout << "Data sended to server" << endl;
- }
- }
- }
- WSACleanup();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement