First of all you need to know that in the browser to browse the virtual host, you must use the Hosts file or domain Name System (DNS) to implement host name to IP address resolution. You can use the Hosts file or DNS in the LAN, only DNS is available on the Internet.
1. When the user enters a domain name, take Baidu as an example (www.baidu.com).
2. First go to the C:\WINDOWS\SYSTEM32\DRIVERS\ETC directory with the Hosts file to query the existence of the relevant IP, if there is access to the IP address.
3. There is no such domain name resolution, then the DNS lookup to the public network.
When you visit the domain name exception, the hosts file may have been modified or DNS has been hijacked.
Solution:
1. First check your C:\WINDOWS\SYSTEM32\DRIVERS\ETC directory under the Hosts file to see if there is a domain name forced to IP, some words to remove this option. Unable to find file settings hidden file is visible.
2.DNS was hijacked or tampered with. You can manually modify the local computer's DNS, default to NULL as, you can set the preferred setting to: 114.114.114.114, the alternate setting is: 114.114.115.115; and check the virus. Or your router has been tampered with (the password set is too weak), it is recommended to modify it with the repair tool.
The above describes the network normal domain name access to the cause of the problem, then the following will take you to use C # to make a Hosts modification tool (you can study, understand the technology, but not to spoof others ):
Private Static voidUpdatehosts (stringIpstringdomain) { stringPath =@"C:\WINDOWS\system32\drivers\etc\hosts"; //normally this file is read-only, so it is read-only before writingFile.setattributes (Path, file.getattributes (path) & (~fileattributes.readonly));//Cancel Read-only//1. Create a file streamFileStream FS =ip==""?NewFileStream (Path, FileMode.Create):NewFileStream (path, filemode.append); //2. Creating a writerStreamWriter SW =NewStreamWriter (FS, Encoding.UTF8); //3. Start writing BOOLresult =false;//identifies whether the write succeeded Try{StringBuilder SB=NewStringBuilder (); Sb. Append (IP);//IP AddressSb. Append (" "); Sb. Append (domain);//websiteSW. WriteLine (sb.) ToString ()); Result=true; } Catch(Exception ex) {result=false; } finally { //4. Turn off the writer if(SW! =NULL) {SW. Close (); } //5. Close the file stream if(FS! =NULL) {fs. Close (); } } if(Result = =true) {MessageBox.Show ("Success! "); File.setattributes (Path, file.getattributes (path)| FILEATTRIBUTES.READONLY);//set read-only } Else{MessageBox.Show ("failed! "); return; } }
In the URL section input www.baidu.com, after adding try, you can also visit Baidu?
It doesn't matter, after you click Clear, you can visit again!
Source Address: Https://files.cnblogs.com/files/jiyuwu/HostsEdit.zip
Network normal only their own access to the site anomaly once let you doubt, is not black! How the domain name resolution exception occurs, how to solve the process and C # programming implementation A key to modify the Hosts file