• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

C# [C#] Manipulate Hosts File

Status
Not open for further replies.

sQuo

~ KillmeMories ~
Shadow
User
Joined
Oct 16, 2011
Messages
5,851
Reputation
0
Reaction score
22,904
Points
688
Credits
0
‎13 Years of Service‎
24%
You can redirect any DNS request by adding the fake-ip in the Hosts file. This little code snippet demonstate how:

Code:
>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace HostsManipulation {
   class Program {

       private static string hosts_file = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\drivers\etc\hosts";

       static void Main(string[] args) {
           manipulate();
           try
           {
           Console.Read();
           }
           catch(Exeption e)
           {}   

       }


       private static void manipulate() {
           try {
               StreamReader sr = new StreamReader(hosts_file);
               string file_string = sr.ReadToEnd();
               sr.Close();
               file_string += "127.0.0.1      google.de\n";
               StreamWriter sw = new StreamWriter(hosts_file);
               sw.Write(file_string);
               sw.Close();
               Console.WriteLine("Done!");
           } catch(Exception e) {
               Console.WriteLine(e.Message);
           }
       }
   }
}
by Crushpest

 
Status
Not open for further replies.
Back
Top