{"id":1480,"date":"2023-02-08T03:17:46","date_gmt":"2023-02-07T19:17:46","guid":{"rendered":"http:\/\/175.24.184.226\/?p=1480"},"modified":"2023-02-08T03:17:46","modified_gmt":"2023-02-07T19:17:46","slug":"proxy%e5%a4%9a%e7%ba%bf%e7%a8%8b","status":"publish","type":"post","link":"\/?p=1480","title":{"rendered":"proxy\u591a\u7ebf\u7a0b"},"content":{"rendered":"<p>\u67d0ip\u4ee3\u7406\u7f51\u7ad9\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u5176\u4e2d\u7684\u591a\u7ebf\u7a0b\u7528\u6cd5\u6709\u503c\u5f97\u501f\u9274\u7684\u5730\u65b9\uff0c\u7279\u6b64\u8bb0\u5f55<\/p>\n<pre><code class=\"language-python\">import json\nimport threading\nimport time\nimport requests\nfrom fake_useragent import FakeUserAgent\nua = FakeUserAgent()\nprint(ua.random)\n&#039;&#039;&#039;\n\u9996\u5148\u5c06\u5916\u7f51IP\u52a0\u5165\u767d\u540d\u5355\n&#039;&#039;&#039;\n\nheaders = {\n    &quot;User-Agent&quot;: &quot;Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko\/20100101 Firefox\/85.0&quot;,\n    &quot;Accept&quot;: &quot;text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,*\/*;q=0.8&quot;,\n    &quot;Accept-Language&quot;: &quot;zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2&quot;,\n    &quot;Accept-Encoding&quot;: &quot;gzip, deflate, br&quot;\n}\n\n# \uff08http\uff09\u4e1a\u52a1\u903b\u8f91\ndef execute_http(proxy_addr):\n    # targetUrl = &#039;http:\/\/ip234.in\/ip.json&#039;\n    targetUrl = &#039;https:\/\/www.bitechan.tv\/bapi\/composite\/v1\/public\/cms\/article\/list\/query?type=1&amp;pageNo=1&amp;pageSize=10&#039;\n\n    proxies = {\n        &#039;http&#039;: &#039;http:\/\/{}&#039;.format(proxy_addr),\n        &#039;https&#039;: &#039;http:\/\/{}&#039;.format(proxy_addr),\n    }\n    res = &quot;&quot;\n\n    while True:\n        try:\n            start_time = time.time()\n            res = requests.get(targetUrl, proxies=proxies, timeout=5)\n            # print(res.status_code)\n            end = time.time()\n            print(&quot;\u8017\u65f6\uff1a&quot;+str(end-start_time))\n            # print(res.status_code, &quot;***&quot;, res.text)\n            print(res.status_code)\n            # print(json.dumps(res.text, ensure_ascii=False, indent=4))\n            break\n        except Exception as e:\n            print(e)\n            break\n    return\n\n# (socks5) \u4e1a\u52a1\u903b\u8f91\ndef execute_socks5(proxy_addr):\n    targetUrl = &#039;http:\/\/ip234.in\/ip.json&#039;\n\n    proxies = {\n        &#039;http&#039;: &#039;socks5h:\/\/{}&#039;.format(proxy_addr),\n        &#039;https&#039;: &#039;socks5h:\/\/{}&#039;.format(proxy_addr),\n    }\n    res = &quot;&quot;\n\n    while True:\n        try:\n            res = requests.get(targetUrl, proxies=proxies, timeout=5)\n            # print(res.status_code)\n            print(res.status_code, &quot;***&quot;, res.text)\n            break\n        except Exception as e:\n            print(e)\n            break\n    return\n\nclass ThreadFactory(threading.Thread):\n    def __init__(self, proxy_addr, proxy_type):\n        threading.Thread.__init__(self)\n        self.proxy_addr = proxy_addr\n        self.proxy_type = proxy_type\n\n    def run(self):\n        if self.proxy_type == &quot;socks5&quot;:\n            execute_socks5(self.proxy_addr)\n        else:\n            execute_http(self.proxy_addr)\n\ndef test_http():\n    # \u4e00\u6b21\u63d05\u4e2a (text\u683c\u5f0f)\n    get_proxy_url = &#039;http:\/\/list.rola.info:8088\/user_get_ip_list?token=Dsw7MWeygNpozDJf1669733924529&amp;qty=5&amp;country=&amp;state=&amp;city=&amp;time=5&amp;format=txt&amp;protocol=http&amp;filter=1&#039;\n\n    while True:\n        try:\n            resp = requests.get(url=get_proxy_url, timeout=5)\n            if resp.status_code != 200:\n                print(&quot;\u63d0\u53d6IP\u5931\u8d25&quot;)\n                time.sleep(1)\n                continue\n            ips = resp.text.split(&quot;\\r\\n&quot;)\n            threads = []\n            for ip in ips:\n                threads.append(ThreadFactory(ip, &quot;http&quot;))\n            for t in threads:\n                t.start()\n                time.sleep(0.01)\n            for t in threads:\n                t.join()\n\n            # break\n            time.sleep(1)\n        except Exception as e:\n            print(e)\n\ndef test_socks5():\n    # \u4e00\u6b21\u63d05\u4e2a (text\u683c\u5f0f)\n    get_proxy_url = &#039;http:\/\/list.rola.info:8088\/user_get_ip_list?token=TOKEN&amp;qty=5&amp;country=&amp;state=&amp;city=&amp;time=5&amp;format=txt&amp;protocol=http&amp;filter=1&#039;\n\n    while True:\n        try:\n            resp = requests.get(url=get_proxy_url, timeout=5)\n            if resp.status_code != 200:\n                print(&quot;\u63d0\u53d6IP\u5931\u8d25&quot;)\n                time.sleep(1)\n                continue\n            ips = resp.text.split(&quot;\\r\\n&quot;)\n            threads = []\n            for ip in ips:\n                threads.append(ThreadFactory(ip, &quot;socks5&quot;))\n            for t in threads:\n                t.start()\n                time.sleep(0.01)\n            for t in threads:\n                t.join()\n\n            # break\n            time.sleep(1)\n        except Exception as e:\n            print(e)\n\nif __name__ == &quot;__main__&quot;:\n    # \u6d4b\u8bd5http\n    # test_http()\n    ...\n    # \u6d4b\u8bd5socks5\n    # test_socks5()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u67d0ip\u4ee3\u7406\u7f51\u7ad9\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u5176\u4e2d\u7684\u591a\u7ebf\u7a0b\u7528\u6cd5\u6709\u503c\u5f97\u501f\u9274\u7684\u5730\u65b9\uff0c\u7279\u6b64\u8bb0\u5f55 import json import threading impo   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[32],"tags":[],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1480"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1480"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1480\/revisions"}],"predecessor-version":[{"id":1481,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1480\/revisions\/1481"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1480"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}