{"id":1577,"date":"2020-05-04T22:36:00","date_gmt":"2020-05-04T14:36:00","guid":{"rendered":"https:\/\/www.yumefx.com\/?p=1577"},"modified":"2021-03-02T21:33:36","modified_gmt":"2021-03-02T13:33:36","slug":"python%e4%bd%bf%e7%94%a8socks5%e4%bb%a3%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.yumefx.com\/?p=1577","title":{"rendered":"python\u4f7f\u7528socks5\u4ee3\u7406"},"content":{"rendered":"\n<p>\u5f53\u901a\u8fc7python\u722c\u866b\u722c\u53d6\u5916\u7f51\u8d44\u6e90\uff0cpython\u9700\u8981\u901a\u8fc7socks5\u7b49\u4ee3\u7406\u8fde\u63a5\u7f51\u7edc\uff0c\u8fd9\u91cc\u8bb0\u5f55\u4e00\u4e0b\u4e24\u79cd\u5e38\u7528\u65b9\u6cd5\u3002<\/p>\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u4fee\u6539\u5185\u7f6epy\u5e93<\/h1>\n<div>\n<p>\u5f53\u4f7f\u7528urllib\u6216\u8005socket\u7b49\u5185\u7f6e\u5e93\u8fde\u63a5\u7f51\u7edc\u65f6\uff0c\u5206\u522b\u4fee\u6539urllib.py\u6216\u8005socket.py\u6587\u4ef6\u3002<\/p>\n<p>\u4e0d\u8fc7\u4fee\u6539\u4ee5\u540e\uff0c\u518d\u4f7f\u7528\u5176\u4ed6python\u7a0b\u5e8f\u65f6\u4e5f\u4f1a\u53d7\u5230\u5f71\u54cd\uff0c\u9700\u8981\u8bb0\u5f97\u518d\u6539\u56de\u6765\u3002<\/p>\n<p>\u6216\u8005\u4f7f\u7528pyenv\u6216\u8005\u7c7b\u4f3c\u7684\u5de5\u5177\uff0c\u4f7f\u8be5\u7a0b\u5e8f\u4f7f\u7528\u72ec\u7acb\u7684\u865a\u62dfpython\u73af\u5883\uff0c\u9632\u6b62\u5f71\u54cd\u5176\u4ed6\u7a0b\u5e8f\u3002<\/p>\n\u4fee\u6539urllib.py<\/div>\n\n\n\n<pre>\n<span>import socks <\/span>\n<span>import socket<\/span>\n<span>socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, &quot;127.0.0.1&quot;, 1080) <\/span>\n<span>socket.socket = socks.socksocket<\/span>\n<\/pre>\n\n\n\n<p>\u4fee\u6539socket.py<\/p>\n\n\n\n<pre>\n<span>socket = SocketType = _socketobject <\/span>\n<span># \u5728socket.py\u627e\u5230\u8fd9\u4e00\u884c <\/span>\n<span># \u5728\u4e0b\u9762\u6dfb\u52a0\u4e0b\u9762\u7684\u4ee3\u7801<\/span>\n<span><\/span>\n<span>import socks <\/span>\n<span>socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, &quot;127.0.0.1&quot;, 1080) <\/span>\n<span>socket = socks.socksocket<\/span>\n<\/pre>\n\n\n\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u4f7f\u7528PySocks<\/h1>\n<p>PySocks\u662f\u4e00\u4e2a\u57fa\u4e8ePython\u7684SOCKS\u4ee3\u7406\u5ba2\u6237\u7aef\uff0c\u5b83\u662fSocksiPy\u7684\u4e00\u4e2a\u5206\u652f\uff0c\u4fee\u6539\u4e86\u4e00\u4e9bbug\u548c\u589e\u52a0\u4e86\u4e00\u4e9b\u989d\u5916\u529f\u80fd\u3002<\/p>\n<h2>\u00a0<\/h2>\n<h2>\u5b89\u88c5<\/h2>\n\n\n\n<pre>\n<span>git clone https:\/\/github.com\/Anorov\/PySocks<\/span>\n<span>cd PySocks<\/span>\n<span>python setup.py install<\/span>\n<\/pre>\n\n\n\n<p>\u6216\u8005\u76f4\u63a5<code>pip install PySocks<\/code><\/p>\n<h2>\u00a0<\/h2>\n<h2>\u4f7f\u7528<\/h2>\n\n\n\n<pre>\n<span>import socket<\/span>\n<span>import socks<\/span>\n<span><\/span>\n<span>socks.set_default_proxy(socks.SOCKS5, &quot;127.0.0.1&quot;, 1080)<\/span>\n<span>socket.socket = socks.socksocket<\/span>\n<span><\/span>\n<span>response = request.get(&quot;www.google.com&quot;)<\/span>\n<\/pre>\n\n\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5f53\u4f17\u4eba\u90fd\u54ed\u65f6\uff0c<\/p>\n<p>\u5e94\u8be5\u5141\u8bb8\u6709\u7684\u4eba\u4e0d\u54ed\u3002<\/p>\n<p>\u5f53\u54ed\u6210\u4e3a\u4e00\u79cd\u8868\u6f14\u65f6\uff0c<\/p>\n<p>\u66f4\u5e94\u8be5\u5141\u8bb8\u6709\u7684\u4eba\u4e0d\u54ed\u3002<\/p>\n<p style=\"text-align: right;\">\u2014\u2014\u83ab\u8a00<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u901a\u8fc7python\u722c\u866b\u722c\u53d6\u5916\u7f51\u8d44\u6e90\uff0cpython\u9700\u8981\u901a\u8fc7socks5\u7b49\u4ee3\u7406\u8fde\u63a5\u7f51\u7edc\uff0c\u8fd9\u91cc\u8bb0\u5f55\u4e00\u4e0b\u4e24\u79cd\u5e38\u7528\u65b9\u6cd5\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1578,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,4],"tags":[37,36,14],"_links":{"self":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts\/1577"}],"collection":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1577"}],"version-history":[{"count":0,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts\/1577\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/media\/1578"}],"wp:attachment":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}