Advertisement
rdsedmundo

Hosts Controller API

Sep 20th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1.     /* # Hosts Controller [API]
  2.      * By Kyl3   - http://pastebin.com/u/Kyl3
  3.      * #         - http://hack4you.net/
  4.      * #         - (c) 2012
  5.      */
  6.  
  7.  
  8.     class ClBlock
  9.     {
  10.         public static void HBlock(string URL)
  11.         {
  12.             if (URL.Contains("http://") || URL.Contains("https://")) URL = URL.Split(new string[] { "//" }, StringSplitOptions.None)[1];
  13.             if (!URL.Contains("www")) URL = "www." + URL;
  14.  
  15.             string path = @"C:\Windows\System32\drivers\etc\hosts";
  16.             TextWriter HWrite = File.AppendText(path);
  17.             HWrite.WriteLine("\r\n0.0.0.0 " + URL + "\r\n0.0.0.0 " + URL.Replace("www.", ""));
  18.             HWrite.Close();
  19.         }
  20.  
  21.         public static void HUnBlock(string URL)
  22.         {
  23.             if (URL.Contains("http://") || URL.Contains("https://")) URL = URL.Split(new string[] { "//" }, StringSplitOptions.None)[1];
  24.             if (!URL.Contains("www")) URL = "www." + URL;
  25.  
  26.             string path = @"C:\Windows\System32\drivers\etc\hosts";
  27.             string[] site = URL.Split(new char[] { '.' });
  28.             string[] domain = URL.Split(new char[] { '.' });
  29.             site = site[1].Split(new char[] { '.' });
  30.             domain = domain[2].Split(new char[] { '.' });
  31.             StringBuilder newFile = new StringBuilder();
  32.             string[] temp = { "", "" };
  33.             string[] file = File.ReadAllLines(path);
  34.             int i = 0;
  35.             foreach (string line in file)
  36.             {
  37.                 if (line.Contains(site[0]))
  38.                 {
  39.                     if (i == 0)
  40.                     {
  41.                         temp[1] = line.Replace("0.0.0.0 www." + site[0] + "." + domain[0], "");
  42.                         newFile.Append(temp[1] + "\r\n");
  43.                         i++;
  44.                         continue;
  45.                     }
  46.                     if (i == 1)
  47.                     {
  48.                         temp[0] = line.Replace("0.0.0.0 " + site[0] + "." + domain[0], "");
  49.                         newFile.Append(temp[0] + "\r\n");
  50.                         break;
  51.                     }
  52.                 }
  53.                 else
  54.                 {
  55.                     newFile.Append(line + "\r\n");
  56.                 }
  57.             }
  58.             File.WriteAllText(path, newFile.ToString());
  59.         }
  60.  
  61.         public static void HUnBlockAll()
  62.         {
  63.             string path = @"C:\Windows\System32\drivers\etc\hosts";
  64.             TextWriter HWrite = File.CreateText(path);
  65.             HWrite.Write("");
  66.             HWrite.Close();
  67.         }
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement