如何通过CMD编辑主机文件?

时间:2010-11-19 04:18:56

标签: windows-7 cmd hosts

您好我想直接从命令提示符阻止某些网站。

像这样回应:

0.0.0.0 websitename.com

我该怎么做? (操作系统:Windows 7)

2 个答案:

答案 0 :(得分:38)

echo 0.0.0.0 websitename.com >> %WINDIR%\System32\Drivers\Etc\Hosts

>>echo的输出附加到文件。

请注意,有两个原因可能无法满足您的需要。您可能已经意识到这些,但我提到它们以防万一。

首先,它不会影响Web浏览器,例如,已经解析了当前的“真实”IP地址。因此,它不会立即生效。

其次,它要求您为域中的每个主机名添加一个条目;例如,只需添加websitename.com 阻止www.websitename.com

答案 1 :(得分:21)

使用主持人指挥官。它简单而有力。翻译的描述(来自俄语)here

使用

的示例
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

下载

https://code.google.com/p/hostscmd/downloads/list