Using batch BAT to change multiple methods for hosts _dos/bat

Source: Internet
Author: User
Tags goto

What is hosts:

Hosts is a system file without extensions, you can use Notepad and other tools to open, its role is to use a number of commonly used Web site domain name and its corresponding IP address to establish an association "database", when the user in the browser to enter a need to log in to the URL, The system will first automatically find the corresponding IP address from the Hosts file, once found, the system will immediately open the corresponding Web page, if not found, then the system will be submitted to DNS domain name resolution server IP address resolution.

The specific role of the Hosts file:

Now let's look at how the Hosts file works and what it does in concrete use.
1, speed up the domain name resolution
For Web sites that you want to visit frequently, we can improve the speed of domain resolution by configuring domain name and IP mapping relationships in hosts. Because of the mapping relationship, when we enter the domain name computer can quickly resolve the IP, rather than requesting a DNS server on the network.
2, Convenient LAN users
In many units of the local area network, there will be a server for users to use. However, because the local area network generally rarely set up DNS servers, access to these servers, to enter the difficult to remember the IP address. This is quite troublesome for many people. Now you can give these servers an easy to remember name, and then set up IP mapping in the hosts, so that when the next visit, as long as the name of the server to enter the line.
3, shielding the site
Now a lot of web sites without user consent to install a variety of plug-ins to your computer, some of which may be Trojans or viruses. For these sites we can use the hosts to map the site's domain name to the wrong IP or the local computer's IP, so no access. In Windows systems, the Convention 127.0.0.1 as the IP address of the local computer, and 0.0.0.0 is the wrong IP address.

Change Hosts file batch with bat

@echo off
echo "Please note that your antivirus software prompts, be sure to allow"
@echo  ########################################
@xcopy c:\ Windows\system32\drivers\etc\hosts C:\Windows\system32\drivers\etc\hosts.bak\/d/c/i/y 
@echo  ########### #############################
@echo  Hosts file backup completed, began to modify the Hosts file
@echo 
@echo 117.79.149.116 search.b2b.cn >>c:\windows\system32\drivers\etc\hosts
@echo 117.79.149.116 news.search.b2b.cn >>c : \windows\system32\drivers\etc\hosts
echo   "Hosts file modification completed"
@ipconfig/flushdns
@echo   " Refresh DNS Complete "

echo  Hosts file modified, press any key to restore system original state
@echo
@echo  ################################## ######
@pause > nul
@copy C:\Windows\System32\drivers\etc\hosts.bak\hosts C:\Windows\System32\drivers \etc\hosts/y
@echo 
@echo off
Echo  Hosts file recovery, press any key to exit
@echo 
@pause > nul
@ Exit

Build a local test environment:

@echo off
Echo to build the local test environment
Echo.
C:
CD \
if not exist Lmhy-test\con MD lmhy-test
if exist lmhy-test\hosts.bak goto backup_exists
Echo is creating Backup ...
CD \windows\system32\drivers\etc
copy/y hosts \lmhy-test\hosts.bak > NULL
echo Complete!
Echo.
Goto Backup_start
: backup_exists
echo backup file already exists and does not need to be backed up.
echo
: Backup_start
Echo is writing test data
... echo 127.0.0.1    localhost > Hosts
echo 192.168.1.170  lmhy.com >> hosts
Echo 192.168.3.170  www.lmhy.com >> hosts
echo 192.168.3.170  php.lmhy.com >> hosts
Echo 192.168.3.170  test.lmhy.com >> hosts
echo complete!
Echo.
Echo establishes lmhy Local test environment complete. Press any key to exit
... Pause > Null

To uninstall a local test environment:

@echo off
Echo Uninstall the local test environment
Echo.
C:
CD \
if not exist Lmhy-test\hosts.bak goto backup_not_exists
echo is restoring backup ...
copy/y \lmhy-test\hosts.bak \windows\system32\drivers\etc > Null
CD \windows\system32\drivers\etc
if Exist hosts del/q hosts
Ren hosts.bak hosts
echo complete!
Echo.
echo is removing backup ...
CD \
rmdir/s/q \lmhy-test\
echo Complete!
Echo.
Goto backup_done
: backup_not_exists
echo backup file does not exist and cannot be recovered.

(Note: A 360 installation may appear when you run the Change Warning box, click to run it)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.