Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* # Hosts Controller [API]
- * By Kyl3 - http://pastebin.com/u/Kyl3
- * # - http://hack4you.net/
- * # - (c) 2012
- */
- class ClBlock
- {
- public static void HBlock(string URL)
- {
- if (URL.Contains("http://") || URL.Contains("https://")) URL = URL.Split(new string[] { "//" }, StringSplitOptions.None)[1];
- if (!URL.Contains("www")) URL = "www." + URL;
- string path = @"C:\Windows\System32\drivers\etc\hosts";
- TextWriter HWrite = File.AppendText(path);
- HWrite.WriteLine("\r\n0.0.0.0 " + URL + "\r\n0.0.0.0 " + URL.Replace("www.", ""));
- HWrite.Close();
- }
- public static void HUnBlock(string URL)
- {
- if (URL.Contains("http://") || URL.Contains("https://")) URL = URL.Split(new string[] { "//" }, StringSplitOptions.None)[1];
- if (!URL.Contains("www")) URL = "www." + URL;
- string path = @"C:\Windows\System32\drivers\etc\hosts";
- string[] site = URL.Split(new char[] { '.' });
- string[] domain = URL.Split(new char[] { '.' });
- site = site[1].Split(new char[] { '.' });
- domain = domain[2].Split(new char[] { '.' });
- StringBuilder newFile = new StringBuilder();
- string[] temp = { "", "" };
- string[] file = File.ReadAllLines(path);
- int i = 0;
- foreach (string line in file)
- {
- if (line.Contains(site[0]))
- {
- if (i == 0)
- {
- temp[1] = line.Replace("0.0.0.0 www." + site[0] + "." + domain[0], "");
- newFile.Append(temp[1] + "\r\n");
- i++;
- continue;
- }
- if (i == 1)
- {
- temp[0] = line.Replace("0.0.0.0 " + site[0] + "." + domain[0], "");
- newFile.Append(temp[0] + "\r\n");
- break;
- }
- }
- else
- {
- newFile.Append(line + "\r\n");
- }
- }
- File.WriteAllText(path, newFile.ToString());
- }
- public static void HUnBlockAll()
- {
- string path = @"C:\Windows\System32\drivers\etc\hosts";
- TextWriter HWrite = File.CreateText(path);
- HWrite.Write("");
- HWrite.Close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement