您好,我想直接从命令提示符阻止一些网站。
像这样回声:
0.0.0.0 websitename.com
我怎样才能做到这一点?(操作系统:Windows 7)
echo 0.0.0.0 websitename.com >> %WINDIR%\System32\Drivers\Etc\Hosts
将>>
的输出附加echo
到文件中。
请注意,这可能无法像您希望的那样工作有两个原因。你可能知道这些,但我提到它们以防万一。
首先,它不会影响 Web 浏览器,例如,已经解析了当前的“真实”IP 地址。因此,它不会总是立即生效。
其次,它要求您为域上的每个主机名添加一个条目;例如,仅添加websitename.com
不会阻止www.websitename.com
。
使用主机指挥官。它简单而强大。你可以在这里下载。
hosts add another.dev 192.168.1.1 # Remote host
hosts add test.local # 127.0.0.1 used by default
hosts set myhost.dev # new comment
hosts rem *.local
hosts enable local*
hosts disable localhost
……还有许多其他人……
Usage:
hosts - run hosts command interpreter
hosts <command> <params> - execute hosts command
Commands:
add <host> <aliases> <addr> # <comment> - add new host
set <host|mask> <addr> # <comment> - set ip and comment for host
rem <host|mask> - remove host
on <host|mask> - enable host
off <host|mask> - disable host
view [all] <mask> - display enabled and visible, or all hosts
hide <host|mask> - hide host from 'hosts view'
show <host|mask> - show host in 'hosts view'
print - display raw hosts file
format - format host rows
clean - format and remove all comments
rollback - rollback last operation
backup - backup hosts file
restore - restore hosts file from backup
recreate - empty hosts file
open - open hosts file in notepad