Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.60 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Threading;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Net;
  8. using System.Net.Sockets;
  9.  
  10.  
  11. internal class Data
  12. {
  13.     Dictionary<string, string> array = new Dictionary<string, string>();
  14.     IEnumerable num = new string[] { "user", "password", "host", "port", "type" };
  15.     IEnumerator key, value;
  16.  
  17.     internal string User, Password, Port, Host, Type;
  18.  
  19.     public virtual void Set(IEnumerable args)
  20.     {
  21.         key = num.GetEnumerator();
  22.         value = args.GetEnumerator();
  23.  
  24.         while (key.MoveNext() && value.MoveNext())
  25.         {
  26.             array.Add(key.Current.ToString(), value.Current.ToString());
  27.         };
  28.  
  29.         foreach (var item in array)
  30.         {
  31.             switch (item.Key)
  32.             {
  33.                 case "user": User = item.Value;
  34.                     break;
  35.                 case "password": Password = item.Value;
  36.                     break;
  37.                 case "host": Host = item.Value;
  38.                     break;
  39.                 case "port": Port = item.Value;
  40.                     break;
  41.                 case "type": Type = item.Value;
  42.                     break;
  43.             };
  44.         };
  45.     }
  46. };
  47.  
  48. class Config : Data
  49. {
  50.     public override void Set(IEnumerable arg)
  51.     {
  52.         base.Set(arg);
  53.     }
  54.  
  55.     public Config(ref IEnumerator arg, int i)
  56.     {
  57.         ArrayList list = new ArrayList();
  58.  
  59.         while (arg.MoveNext())
  60.         {
  61.             list.Add(arg.Current);
  62.         };
  63.  
  64.         this.Set((IEnumerable)list);
  65.     }
  66. };
  67.  
  68. class Program : SocketHandler
  69. {
  70.     static List<Config> Config;
  71.     static int Current;
  72.  
  73.     static byte[] data;
  74.  
  75.     static void Init(string[] args)
  76.     {
  77.         Config = new List<Config>();
  78.         IEnumerator ie = args.GetEnumerator();
  79.         Config.Add(new Config(ref ie, args.Length));
  80.         ie = Config.GetEnumerator();
  81.         while (ie.MoveNext()) ;
  82.         Current = 0;
  83.     }
  84.  
  85.     static void Main()
  86.     {
  87.         Init(new string[] { "sergylens", "dr15gera", "ftp.drivehq.com", "21", "FTP" });
  88.  
  89.         Socket socket = new Connection(Config[Current].Host, Convert.ToInt32(Config[Current].Port)).GetSocketFromTcpClient();
  90.         SocketHandler handler = new SocketHandler();
  91.  
  92.         if (socket != null)
  93.         {
  94.             data = new byte[socket.Available];
  95.             Connection.WaitOne();
  96.             socket.BeginReceive(data, 0, socket.Available, SocketFlags.None, new AsyncCallback(handler.Receiving), socket);
  97.         };
  98.        
  99.         Console.ReadLine();
  100.     }
  101.  
  102. };
  103.  
  104. class Connection
  105. {
  106.     static TcpClient Connector;
  107.  
  108.     public Connection(string arg1, int arg2)
  109.     {
  110.         Connector = new TcpClient();
  111.         Connector.BeginConnect(arg1, arg2, new AsyncCallback(Connecting), Connector);
  112.     }
  113.  
  114.     internal TcpClient GetTcpClient()
  115.     {
  116.         return Connector;
  117.     }
  118.  
  119.     internal Socket GetSocketFromTcpClient()
  120.     {
  121.         return Connector.Client;
  122.     }
  123.  
  124.     void Connecting(IAsyncResult result)
  125.     {
  126.         TcpClient client = (TcpClient)result.AsyncState;
  127.         client.EndConnect(result);
  128.         WaitOne();
  129.     }
  130.  
  131.     internal static void WaitOne()
  132.     {
  133.         Thread.Sleep(300);
  134.     }
  135. };
  136.  
  137. class SocketHandler
  138. {
  139.     protected internal void Receiving(IAsyncResult result)
  140.     {
  141.         Socket socket = (Socket)result.AsyncState;
  142.         socket.EndReceive(result);
  143.         Connection.WaitOne();
  144.  
  145.         byte[] data = new byte[socket.Available];
  146.         string text = Encoding.UTF8.GetString(data);
  147.         Console.WriteLine(text);
  148.     }
  149. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement