megabits
V2EX  ›  问与答

求助啊各位。OS X 开机 sudo 启动 python 脚本

  •  
  •   megabits · Sep 12, 2015 · 2460 views
    This topic created in 3987 days ago, the information mentioned may be changed or developed.

    OS X 开机 sudo 启动 python 脚本防 DNS 劫持,脚本在这里 https://github.com/linkerlin/BlackHolePy
    我用一个 shell 脚本来带 python 如下

    !/bin/sh

    cd /Users/Megabits/BlackHolePy-master/
    python dnsproxy.py

    然后在 /Library/LaunchAgents/ 中放了 plist 用于开机启动
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Label</key><string>com.dns</string>
    <key>Program</key><string>/Users/Megabits/BlackHolePy-master/run.sh</string>
    <key>KeepAlive</key><true/>
    <key>NetworkState</key><true/>
    <key>StandardErrorPath</key><string>/var/log/system.log</string>
    <key>LaunchOnlyOnce</key><true/>
    </dict>
    </plist>
    开机虽然脚本启动了,但是本地 DNS 服务器不生效,求解啊

    4 replies    2015-09-12 18:42:15 +08:00
    casparchen
        1
    casparchen  
       Sep 12, 2015 via iPad
    python dnsproxy.py &
    加个&试试
    Daniel65536
        2
    Daniel65536  
       Sep 12, 2015
    很简单,/Library/LaunchAgents/里的 plist 是以当前登录的用户的身份执行的,所以拿不到 root ,所以抢不下 53 端口。你把 plist 丢 /Library/LaunchDaemons 就对了。
    megabits
        3
    megabits  
    OP
       Sep 12, 2015
    @Daniel65536 之前试过了,无用。
    megabits
        4
    megabits  
    OP
       Sep 12, 2015
    @casparchen 测试无用
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3286 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 11:01 · PVG 19:01 · LAX 04:01 · JFK 07:01
    ♥ Do have faith in what you're doing.