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

omn*_*nix 18 cmd hosts windows-7

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

回声如下:

0.0.0.0 websitename.com
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?(操作系统:Windows 7)

And*_*ber 40

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

>>追加的输出echo到文件中.

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

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

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

  • `ipconfig/flushdns`将使您对此文件的更改立即生效 (7认同)

小智 21

使用Hosts Commander.它简单而有力.翻译说明(来自俄语)这里.

使用示例

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
Run Code Online (Sandbox Code Playgroud)

......还有很多人......

救命

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
Run Code Online (Sandbox Code Playgroud)

下载

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