Advertisement
Guest User

Untitled

a guest
Aug 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net.Sockets;
  7. using System.Net;
  8.  
  9. namespace proxy
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             TcpListener server = null;
  16.             TcpClient client = null;
  17.             RequestBuilder requestBuilder = new RequestBuilder();
  18.             //IDictionary<string, string> request = new Dictionary<string, string>();
  19.             try
  20.             {
  21.                 /*
  22.                 Int32 severPort = 443;
  23.                 IPAddress serverAddress = IPAddress.Parse("192.168.1.10");
  24.                 server = new TcpListener(serverAddress, severPort);
  25.                 server.Start();
  26.                 */
  27.                 string clientHostname = "sadistic.pl";
  28.                 Int32 clientPort = 443;
  29.                 //IPAddress clientAddress = IPAddress.Parse("216.58.209.78");
  30.                 client = new TcpClient(clientHostname, clientPort);
  31.  
  32.                 // Buffer for reading data
  33.                 Byte[] bytes = new Byte[256];
  34.                 String data = null;
  35.                 string request = requestBuilder.FormHttpRequest(clientHostname);
  36.                 while (true)
  37.                 {
  38.                     //Console.WriteLine("Waiting for a connection at " + serverAddress + ":" + severPort);
  39.  
  40.                     //client = server.AcceptTcpClient();
  41.                     //Console.WriteLine("Connected!");
  42.                     Console.WriteLine("Sending request");
  43.                     data = null;
  44.  
  45.                     // Get a stream object for reading and writing
  46.                     NetworkStream stream = client.GetStream();
  47.                     stream.Write(Encoding.ASCII.GetBytes(request), 0, Encoding.ASCII.GetBytes(request).Length);
  48.                     int i;
  49.                     // Loop to receive all the data sent by the client.
  50.                     while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
  51.                     {
  52.                         // Translate data bytes to a ASCII string.
  53.                         data = Encoding.ASCII.GetString(bytes, 0, i);
  54.                         Console.WriteLine("Received: {0}", data);
  55.  
  56.                         /*
  57.                         // Process the data sent by the client.
  58.                         data = data.ToUpper();
  59.  
  60.                         byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
  61.  
  62.                         // Send back a response.
  63.                         stream.Write(msg, 0, msg.Length);
  64.                         Console.WriteLine("Sent: {0}", data);
  65.                         */
  66.                     }
  67.  
  68.                     // Shutdown and end connection
  69.                     Console.ReadLine();
  70.                     client.Close();
  71.                 }
  72.             }
  73.             catch (SocketException e)
  74.             {
  75.                 Console.WriteLine("SocketException: {0}", e);
  76.             }
  77.             finally
  78.             {
  79.                 // Stop listening for new clients.
  80.                 server.Stop();
  81.             }
  82.  
  83.  
  84.             Console.WriteLine("\nHit enter to continue...");
  85.             Console.Read();
  86.         }
  87.  
  88.         public static string FormHttpRequest(string address)
  89.         {
  90.             return "null";
  91.         }
  92.  
  93.         public static void CreateRequest()
  94.         {
  95.  
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement