Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.24 KB | None | 0 0
  1. /* external_controls by Flammrock, used for download all external controls here : http://batch-external-controls.site88.net/list.php  */
  2. /* Under MIT/X11 licence. */
  3.  
  4. /*
  5.    The MIT License (MIT)
  6.  
  7.    Copyright (c) 2016 Flammrock
  8.  
  9.    Permission is hereby granted, free of charge, to any person obtaining a copy
  10.    of this software and associated documentation files (the "Software"), to deal
  11.    in the Software without restriction, including without limitation the rights
  12.    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13.    copies of the Software, and to permit persons to whom the Software is
  14.    furnished to do so, subject to the following conditions:
  15.  
  16.    The above copyright notice and this permission notice shall be included in all
  17.    copies or substantial portions of the Software.
  18.  
  19.    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20.    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21.    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22.    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23.    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24.    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25.    SOFTWARE.
  26.  
  27. */
  28.  
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Linq;
  32. using System.Text;
  33. using System.Threading.Tasks;
  34. using System.Net;
  35. using System.IO;
  36.  
  37. namespace get
  38. {
  39.     class Program
  40.     {
  41.         static void Main(string[] args)
  42.         {
  43.             ConsoleColor oldFGcolor = Console.ForegroundColor;
  44.             if (args.Length == 0)
  45.             {
  46.                 Console.Write("[");
  47.                 Console.ForegroundColor = ConsoleColor.Red;
  48.                 Console.Write("ERROR");
  49.                 Console.ForegroundColor = oldFGcolor;
  50.                 Console.Write("] : ");
  51.                 Console.WriteLine("Veuillez indiquer le nom d'une commande externe !");
  52.                 Console.ReadKey();
  53.                 Environment.Exit(0);
  54.             }
  55.             else if ( args[0]=="/?" )
  56.             {
  57.                 Console.ForegroundColor = ConsoleColor.Red;
  58.                 Console.Write("------- Aide Commande externe 'Get' -------\n");
  59.                 Console.ForegroundColor = oldFGcolor;
  60.                 Console.Write("get /? : ");
  61.                 Console.ForegroundColor = ConsoleColor.Blue;
  62.                 Console.Write("Affiche l'aide et la liste des commandes.\n");
  63.                 Console.ForegroundColor = oldFGcolor;
  64.                 Console.Write("get <commande_externe> : ");
  65.                 Console.ForegroundColor = ConsoleColor.Blue;
  66.                 Console.Write("Permet de télécharger n'importe quel commande externe.\n");
  67.                 Console.Write("   Exemple : get SockeT_full\n");
  68.                 Console.ForegroundColor = oldFGcolor;
  69.                 Console.Write("get /list : ");
  70.                 Console.ForegroundColor = ConsoleColor.Blue;
  71.                 Console.Write("Permet d'afficher la liste des commandes externes.\n");
  72.                 Console.ForegroundColor = ConsoleColor.Red;
  73.                 Console.Write("------- 'Get' a été créé par Flammrock -------\n");
  74.                 Console.ForegroundColor = oldFGcolor;
  75.                 Console.Write("\n");
  76.             }
  77.             else if (args[0] == "/list")
  78.             {
  79.                 Console.Write("Connexion sur le serveur en cours...\n");
  80.                 try
  81.                 {
  82.                     string temp = Path.GetTempPath();
  83.                     WebClient wc = new WebClient();
  84.                     wc.DownloadFile("http://batch-external-controls.site88.net/external_controls/list.external_controls.php", temp + "list.external_controls.php");
  85.                     wc.Dispose();
  86.                     int counter = 0;
  87.                     string line;
  88.                     string file_list = temp + "list.external_controls.php";
  89.                     StreamReader file = new StreamReader(file_list);
  90.                     Console.ForegroundColor = ConsoleColor.Red;
  91.                     Console.Write("------- Liste des commandes externes disponibles :\n");
  92.                     Console.ForegroundColor = oldFGcolor;
  93.                     Console.ForegroundColor = ConsoleColor.Blue;
  94.                     while ((line = file.ReadLine()) != null)
  95.                     {
  96.                         Console.WriteLine(line);
  97.                         counter++;
  98.                     }
  99.                     Console.ForegroundColor = ConsoleColor.Red;
  100.                     file.Close();
  101.                     File.Delete(file_list);
  102.                     Console.Write("\n");
  103.                     Console.ForegroundColor = ConsoleColor.Red;
  104.                     Console.Write("{0}", counter);
  105.                     Console.ForegroundColor = oldFGcolor;
  106.                     Console.Write(" commande externe disponible sur le serveur !\n\n");
  107.                     Console.ForegroundColor = ConsoleColor.Red;
  108.                     Console.Write("--------------------------------------------------\n");
  109.                     Console.ForegroundColor = oldFGcolor;
  110.                 }
  111.                 catch
  112.                 {
  113.                     Console.Write("\n[");
  114.                     Console.ForegroundColor = ConsoleColor.Red;
  115.                     Console.Write("ERROR");
  116.                     Console.ForegroundColor = oldFGcolor;
  117.                     Console.Write("] : ");
  118.                     Console.WriteLine("Erreur de connexion sur le serveur ! Veuillez réessayer !");
  119.                     Console.ReadKey();
  120.                 }
  121.                 }
  122.             else
  123.             {
  124.                 Console.Write("Recherche de \"");
  125.                 Console.ForegroundColor = ConsoleColor.Blue;
  126.                 Console.Write(args[0]);
  127.                 Console.ForegroundColor = oldFGcolor;
  128.                 Console.Write("\" sur le serveur...\n");
  129.                 string _url = "http://batch-external-controls.site88.net/external_controls/" + args[0] + ".php";
  130.                 if ( CheckUrl(_url)=="OK" )
  131.                 {
  132.                     Console.Write("\"");
  133.                     Console.ForegroundColor = ConsoleColor.Blue;
  134.                     Console.Write(args[0]);
  135.                     Console.ForegroundColor = oldFGcolor;
  136.                     Console.Write("\" existe\n");
  137.                     try
  138.                     {
  139.                         WebClient wc = new WebClient();
  140.                         wc.DownloadFile("http://batch-external-controls.site88.net/external_controls/" + args[0] + ".exe", args[0]+".exe");
  141.                         wc.Dispose();
  142.                         Console.Write("Téléchargement terminé !");
  143.                     }
  144.                     catch
  145.                     {
  146.                         try
  147.                         {
  148.                             WebClient wc = new WebClient();
  149.                             wc.DownloadFile("http://batch-external-controls.site88.net/external_controls/" + args[0] + ".bat", args[0] + ".bat");
  150.                             wc.Dispose();
  151.                             Console.Write("Téléchargement terminé !");
  152.                         }
  153.                         catch
  154.                         {
  155.                             Console.Write("[");
  156.                             Console.ForegroundColor = ConsoleColor.Red;
  157.                             Console.Write("ERROR");
  158.                             Console.ForegroundColor = oldFGcolor;
  159.                             Console.Write("] : ");
  160.                             Console.WriteLine("Erreur lors du téléchargement !");
  161.                             Console.ReadKey();
  162.                         }
  163.                     }
  164.                 }
  165.                 else
  166.                 {
  167.                     Console.Write("[");
  168.                     Console.ForegroundColor = ConsoleColor.Red;
  169.                     Console.Write("ERROR");
  170.                     Console.ForegroundColor = oldFGcolor;
  171.                     Console.Write("] : ");
  172.                     Console.WriteLine("Cette commande externe n'existe pas !");
  173.                     Console.ReadKey();
  174.                 }
  175.                 Console.ReadKey();
  176.             }
  177.         }
  178.         static string CheckUrl(string myUrl)
  179.         {
  180.             HttpWebRequest _Request;
  181.             HttpWebResponse _Response;
  182.             string message = "";
  183.             if (myUrl != "")
  184.             {
  185.                 try
  186.                 {
  187.                     _Request = (HttpWebRequest)WebRequest.Create(myUrl);
  188.                     _Request.AllowAutoRedirect = false;
  189.                     _Response = (HttpWebResponse)_Request.GetResponse();
  190.                     message = _Response.StatusCode.ToString();
  191.                 }
  192.                 catch (System.Net.WebException ex)
  193.                 {
  194.                     if (ex.Response != null)
  195.                     {
  196.                         message = (((HttpWebResponse)ex.Response).StatusCode).ToString();
  197.                     }
  198.                     else
  199.                         message = ex.Message;
  200.                 }
  201.                 catch (System.UriFormatException ex1)
  202.                 {
  203.                     message = ex1.Message;
  204.                 }
  205.             }
  206.             return message;
  207.         }
  208.     }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement