批处理修改hosts
怎么用批处理修改hosts域名解析文件啊?C:\WINDOWS\system32\drivers\etc\hosts例如加个:0.0.0.0www.qq.com(一定要批...
怎么用批处理修改hosts域名解析文件啊?
C:\WINDOWS\system32\drivers\etc\hosts
例如加个:
0.0.0.0 www.qq.com
(一定要批处理) 展开
C:\WINDOWS\system32\drivers\etc\hosts
例如加个:
0.0.0.0 www.qq.com
(一定要批处理) 展开
展开全部
我以前也做过修改过hosts域名解析文件,下面给你看个范例把
@echo off & title Photoshop CS4\5 联网后注册码无效解决方案
echo 请按任意键执行此方案……
pause>nul
set lj="%systemroot%\System32\drivers\etc\hosts"
echo # Copyright (c) 1993-2006 Microsoft Corp.>%lj%
echo #>>%lj%
echo # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.>>%lj%
echo #>>%lj%
echo # This file contains the mappings of IP addresses to host names. Each>>%lj%
echo # entry should be kept on an individual line. The IP address should>>%lj%
echo # be placed in the first column followed by the corresponding host name.>"%lj%
echo # The IP address and the host name should be separated by at least one>>%lj%
echo # space.>>%lj%
echo #>>%lj%
echo # Additionally, comments (such as these) may be inserted on individual>>%lj%
echo # lines or following the machine name denoted by a '#' symbol.>>%lj%
echo #>>%lj%
echo # For example:>>%lj%
echo #>>%lj%
echo # 102.54.94.97 rhino.acme.com # source server>>%lj%
echo # 38.25.63.10 x.acme.com # x client host>>%lj%
echo.>>%lj%
echo 127.0.0.1 localhost>>%lj%
echo ::1 localhost>>%lj%
echo 127.0.0.1 activate.adobe.com >>%lj%
echo 127.0.0.1 practivate.adobe.com >>%lj%
echo 127.0.0.1 ereg.adobe.com >>%lj%
echo 127.0.0.1 activate.wip3.adobe.com >>%lj%
echo 127.0.0.1 wip3.adobe.com >>%lj%
echo 127.0.0.1 3dns-3.adobe.com >>%lj%
echo 127.0.0.1 3dns-2.adobe.com >>%lj%
echo 127.0.0.1 adobe-dns.adobe.com >>%lj%
echo 127.0.0.1 adobe-dns-2.adobe.com >>%lj%
echo 127.0.0.1 adobe-dns-3.adobe.com >>%lj%
echo 127.0.0.1 ereg.wip3.adobe.com >>%lj%
echo 127.0.0.1 activate-sea.adobe.com >>%lj%
echo 127.0.0.1 wwis-dubc1-vip60.adobe.com >>%lj%
echo 127.0.0.1 activate-sjc0.adobe.com >>%lj%
echo 方案执行完毕!请按回车键退出……
pause>nul
这样就可以达到修改hosts文件的目的,如果是在Vista或WIN7下,要用管理员身份运行,让批处理得到足够的修改权限。
好了,就这样
@echo off & title Photoshop CS4\5 联网后注册码无效解决方案
echo 请按任意键执行此方案……
pause>nul
set lj="%systemroot%\System32\drivers\etc\hosts"
echo # Copyright (c) 1993-2006 Microsoft Corp.>%lj%
echo #>>%lj%
echo # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.>>%lj%
echo #>>%lj%
echo # This file contains the mappings of IP addresses to host names. Each>>%lj%
echo # entry should be kept on an individual line. The IP address should>>%lj%
echo # be placed in the first column followed by the corresponding host name.>"%lj%
echo # The IP address and the host name should be separated by at least one>>%lj%
echo # space.>>%lj%
echo #>>%lj%
echo # Additionally, comments (such as these) may be inserted on individual>>%lj%
echo # lines or following the machine name denoted by a '#' symbol.>>%lj%
echo #>>%lj%
echo # For example:>>%lj%
echo #>>%lj%
echo # 102.54.94.97 rhino.acme.com # source server>>%lj%
echo # 38.25.63.10 x.acme.com # x client host>>%lj%
echo.>>%lj%
echo 127.0.0.1 localhost>>%lj%
echo ::1 localhost>>%lj%
echo 127.0.0.1 activate.adobe.com >>%lj%
echo 127.0.0.1 practivate.adobe.com >>%lj%
echo 127.0.0.1 ereg.adobe.com >>%lj%
echo 127.0.0.1 activate.wip3.adobe.com >>%lj%
echo 127.0.0.1 wip3.adobe.com >>%lj%
echo 127.0.0.1 3dns-3.adobe.com >>%lj%
echo 127.0.0.1 3dns-2.adobe.com >>%lj%
echo 127.0.0.1 adobe-dns.adobe.com >>%lj%
echo 127.0.0.1 adobe-dns-2.adobe.com >>%lj%
echo 127.0.0.1 adobe-dns-3.adobe.com >>%lj%
echo 127.0.0.1 ereg.wip3.adobe.com >>%lj%
echo 127.0.0.1 activate-sea.adobe.com >>%lj%
echo 127.0.0.1 wwis-dubc1-vip60.adobe.com >>%lj%
echo 127.0.0.1 activate-sjc0.adobe.com >>%lj%
echo 方案执行完毕!请按回车键退出……
pause>nul
这样就可以达到修改hosts文件的目的,如果是在Vista或WIN7下,要用管理员身份运行,让批处理得到足够的修改权限。
好了,就这样
推荐于2016-01-05 · 知道合伙人数码行家
可以叫我表哥
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:25897
获赞数:1464972
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。
向TA提问 私信TA
关注
展开全部
通过批处理命令就可以修改hosts文件。下面的例子中,通过批处理命令中的管道命令和逻辑判断,修改hosts文件中原来的映射。
@echo off
cmd /c
cd /d c:
cd %windir%\system32\drivers\etc
for /f "tokens=1,*" %%i in (hosts) do ((echo %%i%%j|find /I "www.dynamipsgui.net")||(echo %%i%%j|find /I "www.dynamipsgui.cn")||echo %%i %%j>>hostsnew.txt)
echo A.B.C.D www.dynamipsgui.net >>hostsnew.txt
echo W.X.Y.Z www.dynamipsgui.cn>>hostsnew.txt
if exist hosts.bak del hosts.bak
rename hosts hosts.bak
rename hostsnew.txt hosts
rem pause
另外还需要注意,只有系统管理员权限才可以修改hosts文件,如果不想逐个电脑修改,可以通过组策略中的开机或者关机脚本来执行这个批处理修改hosts文件。
@echo off
cmd /c
cd /d c:
cd %windir%\system32\drivers\etc
for /f "tokens=1,*" %%i in (hosts) do ((echo %%i%%j|find /I "www.dynamipsgui.net")||(echo %%i%%j|find /I "www.dynamipsgui.cn")||echo %%i %%j>>hostsnew.txt)
echo A.B.C.D www.dynamipsgui.net >>hostsnew.txt
echo W.X.Y.Z www.dynamipsgui.cn>>hostsnew.txt
if exist hosts.bak del hosts.bak
rename hosts hosts.bak
rename hostsnew.txt hosts
rem pause
另外还需要注意,只有系统管理员权限才可以修改hosts文件,如果不想逐个电脑修改,可以通过组策略中的开机或者关机脚本来执行这个批处理修改hosts文件。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
@echo off
echo.>>"C:\WINDOWS\system32\drivers\etc\hosts"
echo 0.0.0.0 www.qq.com>>"C:\WINDOWS\system32\drivers\etc\hosts"
echo.>>"C:\WINDOWS\system32\drivers\etc\hosts"
echo 0.0.0.0 www.qq.com>>"C:\WINDOWS\system32\drivers\etc\hosts"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
@echo off
echo 0.0.0.0 www.qq.com>>%Windir%\system32\drivers\etc\hosts
echo 0.0.0.0 www.qq.com>>%Windir%\system32\drivers\etc\hosts
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
@echo off
color 0a
title hosts appender 1.0
SETLOCAL ENABLEDELAYEDEXPANSION
set /a RTN_VAL=0
set ORIGIN_HOSTS=C:\Windows\system32\drivers\etc\hosts
set FILE_HOSTS=hosts.tmp
set FOLDER_HOSTS=hosts.tmp.1
if not exist "%ORIGIN_HOSTS%" (
echo Not exist hosts.
goto NORMAL_EXIT
)
set /a RTN_VAL=0
cd /d "%ORIGIN_HOSTS%" && set /a RTN_VAL=1
if !RTN_VAL! equ 1 (
echo Not a hosts file.
goto NORMAL_EXIT
)
cls
if "%TEMP%" neq "" (
cd /d "%TEMP%"
set /a RTN_VAL=0
cd . > "%FILE_HOSTS%" || set /a RTN_VAL=1
if !RTN_VAL! equ 1 (
cls
echo Can not access to "%FILE_HOSTS%".
goto NORMAL_EXIT
)
) else (
echo Environment Variables - TEMP is empty.
goto NORMAL_EXIT
)
:INPUT_COMMENTS
set /p COMMENTS=Enter comments:
if "%COMMENTS%" equ "" (
goto INPUT_COMMENTS
)
:INPUT_IP_ADDRESS
set /p IP_ADDRESS=Enter IP address:
if "%IP_ADDRESS%" equ "" (
goto INPUT_IP_ADDRESS
)
:INPUT_HOST_NAMES
set /p HOST_NAMES=Enter host names:
if "%HOST_NAMES%" equ "" (
goto INPUT_HOST_NAMES
)
>> "%FILE_HOSTS%" echo.
>> "%FILE_HOSTS%" echo # %COMMENTS%
>> "%FILE_HOSTS%" echo %IP_ADDRESS% %HOST_NAMES%
cls
echo Preview:
type "%FILE_HOSTS%"
echo.
:INPUT_APPEND_CONFIRM
set /p APPEND_CONFIRM=Enter 'Y' append to origin hosts, or 'n' quit.":
if "%APPEND_CONFIRM%" equ "Y" (
set /a RTN_VAL=0
type "%FILE_HOSTS%" >> "%ORIGIN_HOSTS%" || set /a RTN_VAL=1
if !RTN_VAL! equ 0 (
echo Completed successfully.
goto NORMAL_EXIT
) else (
cls
if exist "%FOLDER_HOSTS%" (
rmdir /s /q "%FOLDER_HOSTS%"
)
mkdir "%FOLDER_HOSTS%"
type "%ORIGIN_HOSTS%" > "%FOLDER_HOSTS%\hosts"
type "%FILE_HOSTS%" >> "%FOLDER_HOSTS%\hosts"
set ORIGIN_ATTR=
for /f "tokens=*" %%I in ("%ORIGIN_HOSTS%") do (
set ORIGIN_ATTR=%%~aI
)
if "!ORIGIN_ATTR!" neq "" (
set /a RTN_VAL=0
for /f "tokens=1* delims=-" %%m in ("!ORIGIN_ATTR!") do (
set ORIGIN_ATTR=%%m
set /a RTN_VAL=1
)
if !RTN_VAL! equ 0 (
set ORIGIN_ATTR=
)
) else (
echo Can not obtain file attributes.
goto NORMAL_EXIT
)
attrib -r -a -s -h -i "%FOLDER_HOSTS%\hosts"
set SURPLUS=!ORIGIN_ATTR!
set STR_ATTR=
:PROCESS_ATTR
for /f "tokens=*" %%m in ("!SURPLUS!") do (
set STR_ATTR=!STR_ATTR!+!SURPLUS:~0,1!
set SURPLUS=!SURPLUS:~1!
)
if "!SURPLUS!" neq "" (
goto PROCESS_ATTR
)
if "!STR_ATTR!" neq "" (
rem No 'I'.
attrib !STR_ATTR!"%FOLDER_HOSTS%\hosts"
)
set /a RTN_VAL=0
xcopy /y /q /h /r /k "%FOLDER_HOSTS%\hosts" "%ORIGIN_HOSTS%" || set /a RTN_VAL=1
if !RTN_VAL! equ 0 (
cls
echo Completed successfully.
goto NORMAL_EXIT
) else (
echo Failed.
goto NORMAL_EXIT
)
)
) else if "%APPEND_CONFIRM%" equ "n" (
goto NORMAL_EXIT
) else (
goto INPUT_APPEND_CONFIRM
)
:NORMAL_EXIT
pause
exit
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询