{"id":1385,"date":"2025-02-08T15:23:51","date_gmt":"2025-02-08T07:23:51","guid":{"rendered":"https:\/\/blog.humh.cn\/?p=1385"},"modified":"2025-02-08T15:53:28","modified_gmt":"2025-02-08T07:53:28","slug":"vpn-socks%e4%bb%a3%e7%90%86mac%e7%af%87","status":"publish","type":"post","link":"https:\/\/blog.humh.cn\/?p=1385","title":{"rendered":"VPN Socks\u4ee3\u7406Mac\u7bc7"},"content":{"rendered":"\n<p>\u4e00\u822c\u5927\u5bb6\u5728\u7ffb\u5899\u65f6\u91c7\u7528\u7684 vpn \u8282\u70b9\u53ef\u80fd\u662f\u8282\u70b9\u670d\u52a1\u5546\u4e70\u7684\u73b0\u6210\u8282\u70b9\uff0c\u4ed6\u4eec\u63d0\u4f9b\u53ef\u8ba2\u9605\u7684\u5730\u5740\uff0c\u76f4\u63a5\u901a\u8fc7 Clash \u6216\u7eb8\u98de\u673a\u8ba2\u9605\u3002<\/p>\n\n\n\n<p>\u56e0\u4e3a\u8003\u8651\u5230\u662f\u522b\u4eba\u7684\u673a\u5668\uff0c\u6d41\u91cf\u9700\u8981\u7ecf\u8fc7\u4ed6\u4eec\u673a\u5668\u4ee3\u7406\uff0c\u62c5\u5fc3\u6570\u636e\u5b89\u5168\u9690\u79c1\u6027\u95ee\u9898\u3002\u5982\u679c\u5899\u5916\u673a\u5668\u662f\u6211\u81ea\u5df1\u7684\u673a\u5668\uff0c\u90a3\u5c31\u653e\u5fc3\u4e86\uff0c\u6240\u4ee5\u6211\u4e70\u4e86\u963f\u91cc\u4e91\u9999\u6e2f\u3001\u65b0\u52a0\u5761\u7b49\u8fd9\u79cd\u5899\u5916\u673a\u5668\u6765\u7528\u4e8e\u7ffb\u5899\u3002<br>\u4f46\u82e5\u673a\u5668\u4e0a\u76f4\u63a5\u642d\u5efa vpn \u670d\u52a1\u5982\u7eb8\u98de\u673a\uff0c\u963f\u91cc\u4e91\u4f1a\u76f4\u63a5\u5c01\u7981\u3002\u6240\u4ee5\u91c7\u7528\u4e86\u6700\u76f4\u63a5\u201cssh\u4ee3\u7406\u201d\u7684\u65b9\u5f0f\u7ffb\uff0c\u65e0\u9700\u642d\u5efa\u4efb\u4f55\u670d\u52a1\u3002<\/p>\n\n\n\n<p>\u5982\u672c\u5730\u76f4\u63a5<code>ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=60 -D 6666 -f -q -C -N aliyun.singapor<\/code>\u540e\u5373\u53ef\u901a\u8fc7 6666 \u7aef\u53e3\u8fdb\u884c\u6d41\u91cf\u7684\u8f6c\u53d1\uff0c\u7531\u8be5\u65b0\u52a0\u5761\u673a\u5668\u4ee3\u66ff\u8bf7\u6c42\u5899\u5916\u8d44\u6e90\u3002<\/p>\n\n\n\n<p>\u591a\u6570 Linux \u547d\u4ee4\u4e5f\u652f\u6301\u8fd9\u79cd\u65b9\u5f0f\u8fdb\u884c\u4ee3\u7406\u52a0\u901f\uff0c\u53ef\u89c1 <a href=\"https:\/\/blog.humh.cn\/?p=908\" data-type=\"URL\" data-id=\"https:\/\/blog.humh.cn\/?p=908\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/blog.humh.cn\/?p=908<\/a><br>Chrome \u4e5f\u53ef\u901a\u8fc7 SwitchyOmega \u63d2\u4ef6\u914d\u7f6e socks \u4ee3\u7406\u8fdb\u884c\u7ffb\u5899<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img width=\"1024\" height=\"218\" class=\"wp-image-1386 lazyload\" title=\"VPN Socks\u4ee3\u7406Mac\u7bc7\" src=\"data:image\/gif;base64,R0lGODlhAgABAIAAALGxsQAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==\" data-src=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2025\/02\/20250208141942329-1024x218.png\" alt=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2025\/02\/20250208141942329-1024x218.png\" data-srcset=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2025\/02\/20250208141942329-1024x218.png 1024w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2025\/02\/20250208141942329-300x64.png 300w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2025\/02\/20250208141942329-768x163.png 768w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2025\/02\/20250208141942329-1536x327.png 1536w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2025\/02\/20250208141942329-2048x435.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><\/figure>\n\n\n\n<p>\u5bf9\u4e8e Mac \u6765\u8bf4\uff0c\u4e00\u822c\u6211\u4eec\u901a\u8fc7 Terminal \u6216 Iterm \u7b49\u5de5\u5177\u5f00\u542f\u4e00\u4e2a\u4f1a\u8bdd\uff0c\u5728\u5176\u4e2d\u8f93\u5165 ssh \u547d\u4ee4\u5b8c\u6210 socks \u4ee3\u7406\uff0c\u4f46\u8fd9\u4e2a\u8fdb\u7a0b\u662f\u6302\u5728\u5f00\u542f\u4f1a\u8bdd\u4e0b\uff0c\u82e5\u8be5\u4f1a\u8bdd\u7ed3\u675f\u4ee3\u7406\u4e5f\u5c31\u7ed3\u675f\u4e86\uff0c\u5426\u5219\u4e00\u76f4\u4e0d\u80fd\u5173\u95ed\u4f1a\u8bdd\u3002\u5f53\u7136\u6211\u4eec\u80fd\u4f7f\u7528 tmux \u7b49\u624b\u6bb5\u6302\u5728\u540e\u53f0\u4e0a\uff0c\u4f46\u82e5\u7535\u8111\u91cd\u542f\u4ecd\u9700\u624b\u52a8\u518d\u6572\u4e00\u904d\u547d\u4ee4\u3002<\/p>\n\n\n\n<p>\u4e8e\u662f\u5c31\u5bfb\u601d\u53ef\u901a\u8fc7\u5b9a\u65f6\u4efb\u52a1\u65e0\u8bba\u4efb\u4f55\u65f6\u5019\u90fd\u80fd\u81ea\u52a8\u8fd0\u884c\u547d\u4ee4\uff0c\u4f46\u975e\u6bcf\u6b21\u90fd\u9700\u65b0 ssh\uff0c\u4ec5\u5728\u539f\u5148 ssh \u5df2\u5931\u6548\u518d\u91cd\u8bd5\u3002<br>\u4e0b\u65b9\u662f\u6838\u5fc3\u7684 shell \u811a\u672c\uff0c\u4f1a\u8bb0\u5f55\u65e5\u5fd7\u3002\u5f53\u4ee3\u7406\u65e0\u6cd5\u6210\u529f\u65f6\u4f1a\u5f39\u7a97\u63d0\u793a\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/usr\/bin\/env bash\n\njob_log=$(dirname $0)\/keep_vpn.log\n\necho \"$(date) vpn job start ==============>\" >> ${job_log}\n\n# \u5982\u679c\u7aef\u53e3\u4e0d\u901a\uff0c\u5219\u8bf4\u660essh sockets\u94fe\u63a5\u5df2\u65ad\u3002\u5148\u6e05\u9664\u9057\u7559\u8fdb\u7a0b\uff0c\u7136\u540e\u91cd\u65b0\u94fe\u63a5\u3002\nresult=$(nc -w 1 127.0.0.1 -z 6666 2>&amp;1 | grep 'Connection to 127.0.0.1 port 6666 \\[tcp\/\\*\\] succeeded!' | wc -l | sed 's\/ \/\/g')\n\nnotifaction(){\nosascript &lt;&lt;EOF\ntell application \"System Events\"\nactivate\ndisplay alert \"vpn error\" message \"$1\"\nend tell\nEOF\n}\n\nif [ ${result} != \"1\" ]\nthen\n    old_vpn_proccess_id=$(ps aux | grep '6666' | grep 'ssh' | awk -F ' ' '{print $2}')\n    if [[ ${old_vpn_proccess_id} ]]\n    then\n        echo \"$(date) have old_vpn, id -> ${old_vpn_proccess_id}\" >> ${job_log}\n        echo ${old_vpn_proccess_id} | xargs -I {} kill {}\n        # \u5982\u679c\u8fdb\u7a0b\u4ecd\u5b58\u6d3b\uff0c\u5219\u62a5\u8b66\uff0c\u9700\u6392\u67e5\u6740\u6b7b\u5931\u8d25\u7684\u539f\u56e0\n        if [ $(echo ${old_vpn_proccess_id} | xargs -I {} ps {} | wc -l | sed 's\/ \/\/g') -gt \"1\" ]\n        then\n            notifaction 'kill old proccess error!! please check'\n        fi\n    fi\n\n    # \u5982\u679c\u5899\u53ef\u7528\uff08\u5899\u4e0d\u53ef\u7528\uff0c\u57fa\u672c\u662f\u56e0\u4e3a\u88ab\u7f51\u7edc\u8fd0\u8425\u5546\u9650\u5236\uff09\uff0c\u518dssh\uff0c\u5426\u5219\u4e0d\u5c1d\u8bd5\n    ping_error_count=$(ping -c 1 -t 10 aliyun.singapore | grep '100% packet loss' | wc -l | sed 's\/ \/\/g')\n    if [ ${ping_error_count} -ne \"0\" ]\n    then\n        echo \"fuck!! ip unavailable!!\" >> ${job_log}\n        exit 1\n    fi\n    ssh -o ServerAliveInterval=60 -o  ServerAliveCountMax=60 -D 6666 -f -q -C -N aliyun.singapore\n    if [ $? != \"0\" ]\n    then\n        notifaction 'ssh singapore failure for vpn!! please check'\n    fi\nfi<\/pre>\n\n\n\n<p>\u5f00\u542f\u5b9a\u65f6\u4efb\u52a1(\u5f00\u673a\u81ea\u542f)<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> humh@MacBook-Pro-2 \ue0b0 ~ \ue0b0 crontab -l\n* * * * * cd \/Users\/humh\/cron_job_sh &amp;&amp; .\/keep_vpn.sh >> \/Users\/humh\/cron_job_sh\/keep_vpn.log 2>&amp;1<\/pre>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\">\u73b0\u5b58 BUG\uff1aMac\u672a\u5b8c\u5168\u7761\u7720\u4ecd\u5728\u5de5\u4f5c\u60c5\u51b5\uff0c\u70b9\u51fb\u4e86\u201c\u7761\u7720\u201d\u5408\u4e0a\u7535\u8111\u540e\u4f46\u8bef\u89e6\u5bfc\u81f4\u201c\u5524\u9192\u201d\u4f46\u5df2\u65e0\u7f51\u540e\u4f1a\u4e00\u76f4\u5f39\u7a97\uff08\u5f39\u7a97\u4e2a\u6570\u53d6\u51b3\u4e8e\u671f\u95f4\u5b9a\u65f6\u4efb\u52a1\u5df2\u6267\u884c\u6b21\u6570\uff09\uff0c\u5b9e\u9645\u9884\u671f\u5b9a\u65f6\u4efb\u52a1\u7761\u7720\u671f\u95f4\u5e94\u505c\u6b62\uff0c\u6682\u672a\u7814\u7a76\u6392\u67e5\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"419\" height=\"364\" class=\"wp-image-1391 lazyload\" title=\"VPN Socks\u4ee3\u7406Mac\u7bc7\" src=\"data:image\/gif;base64,R0lGODlhAgABAIAAALGxsQAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==\" data-src=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2025\/02\/20250208154551295.png\" alt=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2025\/02\/20250208154551295.png\" data-srcset=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2025\/02\/20250208154551295.png 826w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2025\/02\/20250208154551295-300x261.png 300w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2025\/02\/20250208154551295-768x668.png 768w\" sizes=\"(max-width: 419px) 100vw, 419px\"><\/figure>\n\n\n\n<p>\u5bf9\u4e8e Windows \u6765\u8bf4\uff0c\u4e00\u822c\u6211\u4eec\u901a\u8fc7 Xshell \u6765\u5b8c\u6210 ssh \u673a\u5668\u8fde\u63a5\u800c\u975e\u672c\u5730\u7ec8\u7aef\u4f1a\u8bdd\u3002Xshell \u53ef\u901a\u8fc7\u4f1a\u8bdd\u914d\u7f6e\u5c31\u80fd\u5b8c\u6210\u81ea\u52a8\u91cd\u8bd5\u4e14 socks \u7aef\u53e3\u66b4\u6f0f\uff0c\u65e0\u9700\u4efb\u4f55\u5f00\u53d1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u822c\u5927\u5bb6\u5728\u7ffb\u5899\u65f6\u91c7\u7528\u7684 vpn \u8282\u70b9\u53ef\u80fd\u662f\u8282\u70b9\u670d\u52a1\u5546\u4e70\u7684\u73b0\u6210\u8282\u70b9\uff0c\u4ed6\u4eec\u63d0\u4f9b\u53ef\u8ba2\u9605\u7684\u5730\u5740\uff0c\u76f4\u63a5\u901a\u8fc7 Clash  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1386,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[53],"tags":[31,113,138],"_links":{"self":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/1385"}],"collection":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1385"}],"version-history":[{"count":4,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/1385\/revisions"}],"predecessor-version":[{"id":1394,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/1385\/revisions\/1394"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/media\/1386"}],"wp:attachment":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}