V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
aocif23
V2EX  ›  问与答

能不能在路由里限制智能电视只能访问乐播

  •  
  •   aocif23 · 356 天前 · 1246 次点击
    这是一个创建于 356 天前的主题,其中的信息可能已经有所发展或是发生改变。

    家里的电视联网主要是为了手机投屏,但电视本身会下载开机广告,能不能用路由器的 iptables 限制电视机 IP 只访问乐播投屏的网址?

    第 1 条附言  ·  352 天前

    确保你的路由器里有dnsmasq, iptables, ipset等命令

    想到了梯子的方法,把这些域名用iptables转到一个不在路由器里使用的端口里

    dnsmasq配置文件(dnsmasq.conf)加入如下内容,用来查看访问过的域名。

    log-queries=true
    log-facility=/tmp/dnsmasq.log
    log-queries=extra
    

    然后用电视连接路由器,比如ip是192.168.2.200,在电视里看网络视频和操作(暂时不要用手机投屏到电视),过了一段时间后在查看路由器的dnsmasq日志,找到192.168.2.200这个ip访问过的网址。

    sed命令删除非192.168.2.200的记录,专注找要阻挡的域名

    sed -i '/from 192\.168\.2\.200/!d' /tmp/dnsmasq.log
    

    找到想要阻挡的域名,然后保存在conf文件里(方便日后添加新的域名),比如路径/etc/storage/dnsmasq/adblock/tv.conf,内容如下,#53为dnsmasq的默认端口,".aaa.ccc"表示所有结尾是.aaa.ccc的域名

    server=/.aaa.ccc/127.0.0.1#53
    ipset=/.aaa.ccc/tvlist
    server=/.bb.ccc/127.0.0.1#53
    ipset=/.bb.ccc/tvlist
    

    dnsmasq的配置文件(dnsmasq.conf)里加载这个conf文件

    conf-dir=/etc/storage/dnsmasq/adblock/tv.conf
    

    再写个shell脚本,保存到/etc/storage/dnsmasq/blocktv.sh(如果你在windows下写的脚本可能要用dos2unix命令转一下,还有脚本的执行权限。)

    blocktv.sh内容

    #!/bin/sh
    
    #加载一些模块,这个仅限我的路由器(刷的是padavan),你的路由器可能不需要。
    modprobe ip_set_hash_net
    modprobe xt_set
    modprobe ipt_REDIRECT
    
    # 将192.168.2.50和192.168.2.200添加到 tvlist 集合中
    # 如果你有多个电视就增加相应的ip
    ipset create tvlist hash:net
    ipset add tvlist 192.168.2.50
    ipset add tvlist 192.168.2.200
    
    # port 1314,随便写不在路由器里使用的端口)
    iptables -t nat -I PREROUTING -s 192.168.2.50 -p tcp -m set --match-set tvlist dst -j REDIRECT --to-port 1314
    iptables -t nat -I OUTPUT -s 192.168.2.50 -p tcp -m set --match-set tvlist dst -j REDIRECT --to-port 1314
    iptables -t nat -I PREROUTING -s 192.168.2.200 -p tcp -m set --match-set tvlist dst -j REDIRECT --to-port 1314
    iptables -t nat -I OUTPUT -s 192.168.2.200 -p tcp -m set --match-set tvlist dst -j REDIRECT --to-port 1314
    

    然后在你的路由器设置每次开机都执行这个脚本。

    最后,发现投屏的域名是 hpplay.cn,不要把它阻挡了。

    10 条回复    2023-05-11 18:16:59 +08:00
    yaott2020
        1
    yaott2020  
       356 天前 via Android
    你需要劫持 dns
    x86
        2
    x86  
       356 天前 via iPhone
    爱快是可以写规则做白名单
    AndrewHenry
        3
    AndrewHenry  
       356 天前
    自建 dns 然后只设置解析乐博的域名
    emma3
        4
    emma3  
       356 天前
    看看是否能 ADB ,然后 disable 所以有关于广告的 apk ,我家的康佳就可以。
    azure2023us559
        5
    azure2023us559  
       356 天前 via Android
    Iptables -I FORWARD -s tvip -j REJECT

    禁止 tv 的 ip 数据包转发
    opengps
        6
    opengps  
       356 天前
    不填写 dns + hosts 设置解析乐播即可
    deorth
        7
    deorth  
       356 天前 via Android
    Puteulanus
        8
    Puteulanus  
       356 天前
    现在的投屏好像是传个网址过去,投的设备自己下载视频播放,禁止所有网络访问的话这种是不是也下不到了
    aocif23
        9
    aocif23  
    OP
       352 天前
    目前这样解决,如果你有更好的方法请说一下。
    aocif23
        10
    aocif23  
    OP
       352 天前
    #6
    @opengps 电视没有 root ,不能修改 hosts


    #8
    @Puteulanus 如果你是手机看本地视频,可以完全阻挡电视访问外网,目前是手机把视频连接传到电视让它播放,手机可以关闭 app 。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1110 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:14 · PVG 02:14 · LAX 11:14 · JFK 14:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.