通过修改hosts文件轻易屏蔽常见视…

之前在百度经验上看到一篇的 怎么样关掉优酷和土豆等在线视频的缓冲广告的文章,简单实用了下发现果真可以用来屏蔽广告,出于好奇心,研究了下文章中方法一所用bat文件代码,发现其实就是在修改和备份hosts文件。
在百度百科 hosts上可以查到:
Hosts是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联“数据库”,当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从Hosts文件中寻找对应的IP地址,一旦找到,系统会立即打开对应网页,如果没有找到,则系统再会将网址提交DNS域名解析服务器进行IP地址的解析。
这样一看其实屏蔽广告的原理自然出来了:
1、hosts中建立了ip地址和域名的映射关系,当请求指定域名的时候,windows先在hosts中查找是否存在映射关系,如果发现了映射ip,则直接使用此发送网络请求,如果没有找到对应关系,则使用DNS解析域名,解析后的ip再作为发送网络请求的目标ip
2、视频中的广告下载到电脑上也是需要发送ip请求的,存储视频广告的主机有他的ip和域名,并且dns可以将此域名解析为实际的ip,那么假如在hosts文件中存有与广告主机域名的ip映射,那么dns就不会解析这些广告主机域名,屏蔽广告的方法就是不把这些域名映射到真实的ip地址,而是映射到一个错误的ip地址,这样广告资源就下载不下来,在视频上就自然没有广告了。
3、错误的ip地址怎么选呢,文章中用的是127.0.0.1,因为:
127.0.0.1是回送地址,指本地机,一般用来测试使用。回送地址(127.x.x.x)是本机回送地址(Loopback Address),即主机IP堆栈内部的IP地址,主要用于网络软件测试以及本地机进程间通信,无论什么程序,一旦使用回送地址发送数据,协议软件立即返回,不进行任何网络传输。(摘自百度百科: 127.0.0.1)

最后我们来解析下hosts文件,并且从百度经验上的那篇文章上提取出常用视频网站上广告的域名(网址):
hosts文件是没有后缀名的文件,是系统文件,可以通过记事本、ultraedit,notepad++等文本处理软件打开,系统中hosts文件存在于:C:\Windows\System32\drivers\etc目录下,最初始的内容是:
#-------------------------分割线-----------------------------------

# 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

#Norton AntiVirus Starts.


#Norton AntiVirus Ends.

127.0.0.1 localhost
#-------------------------分割线-----------------------------------
其中#开头的都是注释,其中解释了hosts的主要作用是简单的使用示例

我从那篇文章上提取出包含的广告域名,做成hosts文件中的映射记录如下,要屏蔽广告的话只需在最后一行记录(127.0.0.1 localhost)后添加如下行后保存即可:
如果什么时候又不想屏蔽广告或者出现其他问题了的话,再删掉一下条目就可以了。
#-------------------------分割线-----------------------------------
127.0.0.1 server1.adpolestar.net
127.0.0.1 mtips.xunlei.com
127.0.0.1 kkpgv.xunlei.com
127.0.0.1 statis.kankan.xunlei.com
127.0.0.1 recommend.xunlei.com
127.0.0.1 cl.kankan.xunlei.com
127.0.0.1 advstat.xunlei.com
127.0.0.1 recommend.xunlei.com
127.0.0.1 cl.kankan.xunlei.com
127.0.0.1 MSG1.client.xunlei.com
127.0.0.1 pubstat.sandai.net
127.0.0.1 biz5.sandai.net
127.0.0.1 mcfg.sandai.net
127.0.0.1 float.sandai.net
127.0.0.1 mpv.sandai.net
127.0.0.1 atm.youku.com
127.0.0.1 Fvid.atm.youku.com
127.0.0.1 html.atm.youku.com
127.0.0.1 valb.atm.youku.com
127.0.0.1 valc.atm.youku.com
127.0.0.1 valo.atm.youku.com
127.0.0.1 valp.atm.youku.com
127.0.0.1 valf.atm.youku.com
127.0.0.1 lstat.youku.com
127.0.0.1 speed.lstat.youku.com
127.0.0.1 urchin.lstat.youku.com
127.0.0.1 stat.youku.com
127.0.0.1 static.lstat.youku.com
127.0.0.1 vid.atm.youku.com
127.0.0.1 walp.atm.youku.com
127.0.0.1 g1.ykimg.com
127.0.0.1 g2.ykimg.com
127.0.0.1 g3.ykimg.com
127.0.0.1 g4.ykimg.com
127.0.0.1 comments.youku.com
127.0.0.1 e.stat.youku.com
127.0.0.1 analytics.ku6.com
127.0.0.1 gug.ku6cdn.com
127.0.0.1 ku6.allyes.com
127.0.0.1 ku6afp.allyes.com
127.0.0.1 pq.stat.ku6.com
127.0.0.1 st.vq.ku6.cn
127.0.0.1 stat0.888.ku6.com
127.0.0.1 stat1.888.ku6.com
127.0.0.1 stat2.888.ku6.com
127.0.0.1 stat3.888.ku6.com
127.0.0.1 static.ku6.com
127.0.0.1 v0.stat.ku6.com
127.0.0.1 v1.stat.ku6.com
127.0.0.1 v2.stat.ku6.com
127.0.0.1 v3.stat.ku6.com
127.0.0.1 adcontrol.tudou.com
127.0.0.1 adplay.tudou.com 
127.0.0.1 stat.tudou.com
127.0.0.1 stats.tudou.com
127.0.0.1 iwstat.tudou.com
127.0.0.1 nstat.tudou.com
127.0.0.1 adextensioncontrol.tudou.com
127.0.0.1 acs.56.com
127.0.0.1 acs.agent.56.com
127.0.0.1 acs.agent.v-56.com
127.0.0.1 bill.agent.56.com
127.0.0.1 bill.agent.v-56.com
127.0.0.1 stat.56.com
127.0.0.1 stat2.corp.56.com
127.0.0.1 union.56.com
127.0.0.1 uvimage.56.com
127.0.0.1 v16.56.com
127.0.0.1 at-img1.tdimg.com
127.0.0.1 at-img2.tdimg.com
127.0.0.1 at-img3.tdimg.com
127.0.0.1 pro.letv.com
127.0.0.1 afp.qiyi.com
127.0.0.1 track.cupid.qiyi.com
127.0.0.1 pic0.qiyipic.com
127.0.0.1 pic1.qiyipic.com
127.0.0.1 pic2.qiyipic.com
127.0.0.1 pic3.qiyipic.com
127.0.0.1 msg.video.qiyi.com
127.0.0.1 show.cupid.qiyi.com
127.0.0.1 api.cupid.qiyi.com
127.0.0.1 widget.weibo.com
127.0.0.1 a.htwisdom.com
127.0.0.1 vinfo.cdn.ppweb.com.cn
127.0.0.1 b.scorecardresearch.com
127.0.0.1 irs01.com
127.0.0.1 rec.inter.qiyi.com
127.0.0.1 score.video.qiyi.com
127.0.0.1 218.5.73.132
127.0.0.1 61.131.89.148
127.0.0.1 dcads.sina.com.cn
127.0.0.1 focusbaiduafp.allyes.com
127.0.0.1 adslvfile.qq.comadslvfile.qq.com
127.0.0.1 game0592.com
127.0.0.1 game.ad1111.com

127.0.0.1 server1.adpolestar.net
127.0.0.1 mtips.xunlei.com
127.0.0.1 kkpgv.xunlei.com
127.0.0.1 statis.kankan.xunlei.com
127.0.0.1 recommend.xunlei.com
127.0.0.1 cl.kankan.xunlei.com
127.0.0.1 advstat.xunlei.com
127.0.0.1 recommend.xunlei.com
127.0.0.1 cl.kankan.xunlei.com
127.0.0.1 MSG1.client.xunlei.com
127.0.0.1 pubstat.sandai.net
127.0.0.1 biz5.sandai.net
127.0.0.1 mcfg.sandai.net
127.0.0.1 float.sandai.net
127.0.0.1 mpv.sandai.net
127.0.0.1 atm.youku.com
127.0.0.1 Fvid.atm.youku.com
127.0.0.1 html.atm.youku.com
127.0.0.1 valb.atm.youku.com
127.0.0.1 valc.atm.youku.com
127.0.0.1 valo.atm.youku.com
127.0.0.1 valp.atm.youku.com
127.0.0.1 valf.atm.youku.com
127.0.0.1 lstat.youku.com
127.0.0.1 speed.lstat.youku.com
127.0.0.1 urchin.lstat.youku.com
127.0.0.1 stat.youku.com
127.0.0.1 static.lstat.youku.com
127.0.0.1 vid.atm.youku.com
127.0.0.1 walp.atm.youku.com
127.0.0.1 g1.ykimg.com
127.0.0.1 g2.ykimg.com
127.0.0.1 g3.ykimg.com
127.0.0.1 g4.ykimg.com
127.0.0.1 comments.youku.com
127.0.0.1 e.stat.youku.com
127.0.0.1 analytics.ku6.com
127.0.0.1 gug.ku6cdn.com
127.0.0.1 ku6.allyes.com
127.0.0.1 ku6afp.allyes.com
127.0.0.1 pq.stat.ku6.com
127.0.0.1 st.vq.ku6.cn
127.0.0.1 stat0.888.ku6.com
127.0.0.1 stat1.888.ku6.com
127.0.0.1 stat2.888.ku6.com
127.0.0.1 stat3.888.ku6.com
127.0.0.1 static.ku6.com
127.0.0.1 v0.stat.ku6.com
127.0.0.1 v1.stat.ku6.com
127.0.0.1 v2.stat.ku6.com
127.0.0.1 v3.stat.ku6.com
127.0.0.1 adcontrol.tudou.com
127.0.0.1 adplay.tudou.com 
127.0.0.1 stat.tudou.com
127.0.0.1 stats.tudou.com
127.0.0.1 iwstat.tudou.com
127.0.0.1 nstat.tudou.com
127.0.0.1 adextensioncontrol.tudou.com
127.0.0.1 acs.56.com
127.0.0.1 acs.agent.56.com
127.0.0.1 acs.agent.v-56.com
127.0.0.1 bill.agent.56.com
127.0.0.1 bill.agent.v-56.com
127.0.0.1 stat.56.com
127.0.0.1 stat2.corp.56.com
127.0.0.1 union.56.com
127.0.0.1 uvimage.56.com
127.0.0.1 v16.56.com
127.0.0.1 at-img1.tdimg.com
127.0.0.1 at-img2.tdimg.com
127.0.0.1 at-img3.tdimg.com
127.0.0.1 pro.letv.com
127.0.0.1 afp.qiyi.com
127.0.0.1 track.cupid.qiyi.com
127.0.0.1 pic0.qiyipic.com
127.0.0.1 pic1.qiyipic.com
127.0.0.1 pic2.qiyipic.com
127.0.0.1 pic3.qiyipic.com
127.0.0.1 msg.video.qiyi.com
127.0.0.1 show.cupid.qiyi.com
127.0.0.1 api.cupid.qiyi.com
127.0.0.1 widget.weibo.com
127.0.0.1 a.htwisdom.com
127.0.0.1 vinfo.cdn.ppweb.com.cn
127.0.0.1 b.scorecardresearch.com
127.0.0.1 irs01.com
127.0.0.1 rec.inter.qiyi.com
127.0.0.1 score.video.qiyi.com
127.0.0.1 218.5.73.132
127.0.0.1 61.131.89.148
127.0.0.1 dcads.sina.com.cn
127.0.0.1 focusbaiduafp.allyes.com
127.0.0.1 adslvfile.qq.comadslvfile.qq.com
127.0.0.1 game0592.com
127.0.0.1 game.ad1111.com
127.0.0.1 server1.adpolestar.net
127.0.0.1 mtips.xunlei.com
127.0.0.1 kkpgv.xunlei.com
127.0.0.1 statis.kankan.xunlei.com
127.0.0.1 recommend.xunlei.com
127.0.0.1 cl.kankan.xunlei.com
127.0.0.1 advstat.xunlei.com
127.0.0.1 recommend.xunlei.com
127.0.0.1 cl.kankan.xunlei.com
127.0.0.1 MSG1.client.xunlei.com
127.0.0.1 pubstat.sandai.net
127.0.0.1 biz5.sandai.net
127.0.0.1 mcfg.sandai.net
127.0.0.1 float.sandai.net
127.0.0.1 mpv.sandai.net
127.0.0.1 atm.youku.com
127.0.0.1 Fvid.atm.youku.com
127.0.0.1 html.atm.youku.com
127.0.0.1 valb.atm.youku.com
127.0.0.1 valc.atm.youku.com
127.0.0.1 valo.atm.youku.com
127.0.0.1 valp.atm.youku.com
127.0.0.1 valf.atm.youku.com
127.0.0.1 lstat.youku.com
127.0.0.1 speed.lstat.youku.com
127.0.0.1 urchin.lstat.youku.com
127.0.0.1 stat.youku.com
127.0.0.1 static.lstat.youku.com
127.0.0.1 vid.atm.youku.com
127.0.0.1 walp.atm.youku.com
127.0.0.1 g1.ykimg.com
127.0.0.1 g2.ykimg.com
127.0.0.1 g3.ykimg.com
127.0.0.1 g4.ykimg.com
127.0.0.1 comments.youku.com
127.0.0.1 e.stat.youku.com
127.0.0.1 analytics.ku6.com
127.0.0.1 gug.ku6cdn.com
127.0.0.1 ku6.allyes.com
127.0.0.1 ku6afp.allyes.com
127.0.0.1 pq.stat.ku6.com
127.0.0.1 st.vq.ku6.cn
127.0.0.1 stat0.888.ku6.com
127.0.0.1 stat1.888.ku6.com
127.0.0.1 stat2.888.ku6.com
127.0.0.1 stat3.888.ku6.com
127.0.0.1 static.ku6.com
127.0.0.1 v0.stat.ku6.com
127.0.0.1 v1.stat.ku6.com
127.0.0.1 v2.stat.ku6.com
127.0.0.1 v3.stat.ku6.com
127.0.0.1 adcontrol.tudou.com
127.0.0.1 adplay.tudou.com 
127.0.0.1 stat.tudou.com
127.0.0.1 stats.tudou.com
127.0.0.1 iwstat.tudou.com
127.0.0.1 nstat.tudou.com
127.0.0.1 adextensioncontrol.tudou.com
127.0.0.1 acs.56.com
127.0.0.1 acs.agent.56.com
127.0.0.1 acs.agent.v-56.com
127.0.0.1 bill.agent.56.com
127.0.0.1 bill.agent.v-56.com
127.0.0.1 stat.56.com
127.0.0.1 stat2.corp.56.com
127.0.0.1 union.56.com
127.0.0.1 uvimage.56.com
127.0.0.1 v16.56.com
127.0.0.1 at-img1.tdimg.com
127.0.0.1 at-img2.tdimg.com
127.0.0.1 at-img3.tdimg.com
127.0.0.1 pro.letv.com
127.0.0.1 afp.qiyi.com
127.0.0.1 track.cupid.qiyi.com
127.0.0.1 pic0.qiyipic.com
127.0.0.1 pic1.qiyipic.com
127.0.0.1 pic2.qiyipic.com
127.0.0.1 pic3.qiyipic.com
127.0.0.1 msg.video.qiyi.com
127.0.0.1 show.cupid.qiyi.com
127.0.0.1 api.cupid.qiyi.com
127.0.0.1 widget.weibo.com
127.0.0.1 a.htwisdom.com
127.0.0.1 vinfo.cdn.ppweb.com.cn
127.0.0.1 b.scorecardresearch.com
127.0.0.1 irs01.com
127.0.0.1 rec.inter.qiyi.com
127.0.0.1 score.video.qiyi.com
127.0.0.1 218.5.73.132
127.0.0.1 61.131.89.148
127.0.0.1 dcads.sina.com.cn
127.0.0.1 focusbaiduafp.allyes.com
127.0.0.1 adslvfile.qq.comadslvfile.qq.com
127.0.0.1 game0592.com
127.0.0.1 game.ad1111.com

127.0.0.1 server1.adpolestar.net
127.0.0.1 mtips.xunlei.com
127.0.0.1 kkpgv.xunlei.com
127.0.0.1 statis.kankan.xunlei.com
127.0.0.1 recommend.xunlei.com
127.0.0.1 cl.kankan.xunlei.com
127.0.0.1 advstat.xunlei.com
127.0.0.1 recommend.xunlei.com
127.0.0.1 cl.kankan.xunlei.com
127.0.0.1 MSG1.client.xunlei.com
127.0.0.1 pubstat.sandai.net
127.0.0.1 biz5.sandai.net
127.0.0.1 mcfg.sandai.net
127.0.0.1 float.sandai.net
127.0.0.1 mpv.sandai.net
127.0.0.1 atm.youku.com
127.0.0.1 Fvid.atm.youku.com
127.0.0.1 html.atm.youku.com
127.0.0.1 valb.atm.youku.com
127.0.0.1 valc.atm.youku.com
127.0.0.1 valo.atm.youku.com
127.0.0.1 valp.atm.youku.com
127.0.0.1 valf.atm.youku.com
127.0.0.1 lstat.youku.com
127.0.0.1 speed.lstat.youku.com
127.0.0.1 urchin.lstat.youku.com
127.0.0.1 stat.youku.com
127.0.0.1 static.lstat.youku.com
127.0.0.1 vid.atm.youku.com
127.0.0.1 walp.atm.youku.com
127.0.0.1 g1.ykimg.com
127.0.0.1 g2.ykimg.com
127.0.0.1 g3.ykimg.com
127.0.0.1 g4.ykimg.com
127.0.0.1 comments.youku.com
127.0.0.1 e.stat.youku.com
127.0.0.1 analytics.ku6.com
127.0.0.1 gug.ku6cdn.com
127.0.0.1 ku6.allyes.com
127.0.0.1 ku6afp.allyes.com
127.0.0.1 pq.stat.ku6.com
127.0.0.1 st.vq.ku6.cn
127.0.0.1 stat0.888.ku6.com
127.0.0.1 stat1.888.ku6.com
127.0.0.1 stat2.888.ku6.com
127.0.0.1 stat3.888.ku6.com
127.0.0.1 static.ku6.com
127.0.0.1 v0.stat.ku6.com
127.0.0.1 v1.stat.ku6.com
127.0.0.1 v2.stat.ku6.com
127.0.0.1 v3.stat.ku6.com
127.0.0.1 adcontrol.tudou.com
127.0.0.1 adplay.tudou.com 
127.0.0.1 stat.tudou.com
127.0.0.1 stats.tudou.com
127.0.0.1 iwstat.tudou.com
127.0.0.1 nstat.tudou.com
127.0.0.1 adextensioncontrol.tudou.com
127.0.0.1 acs.56.com
127.0.0.1 acs.agent.56.com
127.0.0.1 acs.agent.v-56.com
127.0.0.1 bill.agent.56.com
127.0.0.1 bill.agent.v-56.com
127.0.0.1 stat.56.com
127.0.0.1 stat2.corp.56.com
127.0.0.1 union.56.com
127.0.0.1 uvimage.56.com
127.0.0.1 v16.56.com
127.0.0.1 at-img1.tdimg.com
127.0.0.1 at-img2.tdimg.com
127.0.0.1 at-img3.tdimg.com
127.0.0.1 pro.letv.com
127.0.0.1 afp.qiyi.com
127.0.0.1 track.cupid.qiyi.com
127.0.0.1 pic0.qiyipic.com
127.0.0.1 pic1.qiyipic.com
127.0.0.1 pic2.qiyipic.com
127.0.0.1 pic3.qiyipic.com
127.0.0.1 msg.video.qiyi.com
127.0.0.1 show.cupid.qiyi.com
127.0.0.1 api.cupid.qiyi.com
127.0.0.1 widget.weibo.com
127.0.0.1 a.htwisdom.com
127.0.0.1 vinfo.cdn.ppweb.com.cn
127.0.0.1 b.scorecardresearch.com
127.0.0.1 irs01.com
127.0.0.1 rec.inter.qiyi.com
127.0.0.1 score.video.qiyi.com
127.0.0.1 218.5.73.132
127.0.0.1 61.131.89.148
127.0.0.1 dcads.sina.com.cn
127.0.0.1 focusbaiduafp.allyes.com
127.0.0.1 adslvfile.qq.comadslvfile.qq.com
127.0.0.1 game0592.com
127.0.0.1 game.ad1111.com

#-------------------------分割线-----------------------------------





你可能感兴趣的:(通过修改hosts文件轻易屏蔽常见视…)