请问如何做一个添加hosts的批处理?
发布网友
发布时间:2022-05-20 10:05
我来回答
共3个回答
热心网友
时间:2022-05-26 12:08
@echo off
set hostfile=%windir%\system32\drivers\etc\hosts
set ip=%1
set domain=%2
set pause=%3
if "%ip%"=="" goto _use
if "%domain%"=="" goto _use
type %hostfile% | find /i "%domain%"
if errorlevel 1 goto _AddHosts
goto _quit
:_Addhosts
echo %ip% %domain%>> %hostfile%
chcp 936
type %hostfile%
if "%pause%"=="1" pause
goto _quit
:_use
type %hostfile%
echo.
echo ==================================================================
echo AddHost : Add an IP/Domain pair to your system hosts file.
echo Usage: AddHost IP Domain [1]
echo 1: Pause to display hosts file contents after added host.
echo.
goto _quit
:_quit
热心网友
时间:2022-05-26 12:08
%ip% >> %path%\host
热心网友
时间:2022-05-26 12:09
echo 127.0.0.1>>%systemroot%\System32\drivers\etc\hosts