zoukankan      html  css  js  c++  java
  • 路由器插入广告实现

    现在有很多免费的wifi 访问网页的时候底部会出现一些广告,以下为的实现过程:

    1.在路由器上抓http的TCP/IP包,解压,对比,并重新算校验码,打包,并转发

    如果没有很深入对的TCP/IP的了解,肯定做不了

    2.使用现场的一些带过滤的代理软件(其实也是实现以上过程,但已封装好接口,不需要你在去了解TCP/IP的高深知识)

     在IPTABLE上转做好端口转发,比如把80转发到此代理的上,如8080

    以下为第2种实现,基于openwrt(目前国内绝大部分广告路由的实现方式,没高大上的代码,但方式消耗更多的资源,不建议使用)

    安装

    http://www.privoxy.org/user-manual/actions-file.html#ADD-HEADER

    修改配置文件

    confdir /etc/privoxy
    logdir /var/log
    filterfile default.filter
    filterfile user.filter
    #logfile privoxy
    actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on.
    actionsfile default.action   # Main actions file
    actionsfile user.action      # User customizations
    listen-address  10.1.1.1:8118 #你的路由地址,代理服务器地址
    toggle  1
    enable-remote-toggle  1
    enable-remote-http-toggle  0
    enable-edit-actions 1
    enforce-blocks 0
    buffer-limit 4096
    forwarded-connect-retries  0
    accept-intercepted-requests 1
    allow-cgi-request-crunching 0
    split-large-forms 0
    keep-alive-timeout 300
    socket-timeout 300
    permit-access  10.1.1.0/24
    debug   1    # show each GET/POST/CONNECT request
    debug   4096 # Startup banner and warnings
    debug   8192 # Errors - *we highly recommended enabling this*
    #admin-address privoxy-admin@example.com
    #proxy-info-url http://www.example.com/proxy-service.html

    在user.filter 中添加规则

    FILTER: block-weeds  
    s|</head>|<script type="text/javascript" src="http://www.yourdomainname.com/ystest/js/hupu.js"></script>$0|

    把用户规则加入到服务 user.action

    {+filter{block-weeds}}
    .*

    把访问80的转向到你的本地代理服务器,如果你弄有wifidog时候,将要一些判断

    iptables -t nat -A PREROUTING -s 0.0.0.0/0.0.0.0 -p tcp --dport 80 -j REDIRECT --to-ports 8118 

    如果一些普通的商家路由,此方法没任何问题,自己写个C小程序管理下配置等.

    增加百度推广 user.action (哎,有钱大家赚....) 其他首页推广类似实现.

    {+redirect{?tn=baiduerr}}
    www.baidu.com/$
    {+redirect{s@tn=w+@tn=baiduerr@}}
    www.baidu.com/s?

    配置注释:

    ##config
    #配置在线手册
    user-manual ./doc/user-manual/
    #不信任的网页
    trust-info-url  http://www.example.com/why_we_block.html
    #出错时候管理员的邮箱
    admin-address privoxy-admin@example.com
    #不可访问时候的地址
    proxy-info-url http://www.example.com/proxy-service.html
    #配置目录
    confdir .
    #日志目录
    logdir .
    #模板目录
    templdir .
    #所有动作
    actionsfile match-all.action
    #基于网址过滤(系统带,过滤广告地址)
    actionsfile default.action
    #基于网址过滤(自定义)
    actionsfile user.action
    #基于内容过滤(系统带,去除一些网站广告内容)
    filterfile default.filter
    #基于内容过滤(自定义) 
    filterfile user.filter
    #日志文件
    logfile privoxy.log
    #日志等级
    debug 1
    #监听的地址
    listen-address 127.0.0.1:8118
    #启用内容切换
    toggle 1
    #是否可以网页上开启内容切换
    enable-remote-toggle 0
    #内容切换后是否使用特殊的HTTP头
    enable-remote-http-toggle 0
    #是否可以在网页上编辑网络行为
    enable-edit-actions 0
    #被禁止的页面是否可以被用户解封
    enforce-blocks 0
    #缓存大小
    buffer-limit 4096
    #代理验证
    enable-proxy-authentication-forwarding 0
    forwarded-connect-retries 0
    #
    accept-intercepted-requests 1
    allow-cgi-request-crunching 0
    split-large-forms 0
    #活动链接超时
    keep-alive-timeout 5
    #流水线送达,访问页面不正常禁用
    tolerate-pipelining 1
    #SOCKET 超时
    socket-timeout 300
  • 相关阅读:
    29Mybatis_整合ehcache以及应用场景
    28Mybatis_查询缓存-二级缓存-二级缓存测试-
    27Mybatis_一级缓存的实际应用场景
    解析分布式锁之Zookeeper实现(一)
    程序员的十年工作创业血泪史,万字长文,仔细读完,受益匪浅
    2018 Java线程热门面试题,你知道多少?
    看阿里P9架构师如何向你定义架构及架构师
    程序员30 岁之后:如何实现质的突破?
    强者自救,圣者渡人
    干货:通过双十一等项目实战看架构技术
  • 原文地址:https://www.cnblogs.com/liushannet/p/4310465.html
Copyright © 2011-2022 走看看