hostsファイルを編集して広告や悪意のあるサイトをブロックする

hoge的hoo速報やそれに似たサイトにアクセスしようとしたら,まるでアドウェアにでも感染しているかのように変なページにリダイレクトされるので,対策してみました。

事の発端

まとめサイト等にアクセスすると稀にaff.chaopengz.cc(アクセスしないで下さい)にリダイレクトされ

怪しげなサイトに飛ばれされました。

アドウェアを疑いましたが怪しげなプロセスも心当たりも見つからず…
どうやら調べてみると広告を悪用したリダイレクトのようで。これはどうしようもないのでそのドメインをhostsで0.0.0.0に書き換えブロックしてしまおうと。

方法

C:\Windows\System32\drivers\etc\hostsがhostsファイルなので,Win+R->C:\Windows\System32\drivers\etcを入力しhostsファイルのあるディレクトリを開く。

hostsファイルをコピーしデスクトップ等の管理者権限が必要ないディレクトリに貼り付け コピーしたhostsファイルをテキストエディタで開き,以下の内容を記述し保存。(#はコメント)(12.7.0.0.1よりも0.0.0.0の方が速いとかなんとか)

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost

#ここから編集
0.0.0.0 aff.chaopengz.cc

youtubeの広告をブロックするには以下を追加すると良い

0.0.0.0 ad.doubleclick.net
0.0.0.0 pubads.g.doubleclick.net
0.0.0.0 googleads.g.doubleclick.net

編集したhostsファイルをC:\Windows\System32\drivers\etc\hostsに上書き保存

DNSを反映させるためコマンドプロンプトDNSキャッシュクリアを行う。Win+R->cmdコマンドプロンプトを起動。 画像 以下コマンドを入力してEnter

ipconfig /flushdns

以下のようになればおk

C:\Users\Shibanyan>ipconfig /flushdns

Windows IP 構成

DNS リゾルバー キャッシュは正常にフラッシュされました。

では確認してみましょう。"aff.chaopengz.cc のサーバーの DNS アドレスが見つかりませんでした。"となりちゃんとブロックされましたね。バンザ~イ!

MCP教科書 Windows 10(試験番号:70-697)

MCP教科書 Windows 10(試験番号:70-697)