{"id":993170,"date":"2024-12-27T08:43:52","date_gmt":"2024-12-27T00:43:52","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/993170.html"},"modified":"2024-12-27T08:43:54","modified_gmt":"2024-12-27T00:43:54","slug":"python%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e4%bb%a3%e7%90%86ip","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/993170.html","title":{"rendered":"python\u5982\u4f55\u4f7f\u7528\u4ee3\u7406ip"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25070705\/727ea0a0-f696-40da-a79b-0f95bab7789f.webp\" alt=\"python\u5982\u4f55\u4f7f\u7528\u4ee3\u7406ip\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u4f7f\u7528\u4ee3\u7406IP\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5982\u4f7f\u7528requests\u5e93\u3001urllib\u5e93\u3001socks\u5e93\u7b49\u3002\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728\u7f51\u7edc\u8bf7\u6c42\u4e2d\u9690\u85cf\u771f\u5b9eIP\u3001\u7a81\u7834IP\u9650\u5236\u3001\u63d0\u9ad8\u533f\u540d\u6027\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528requests\u5e93\u7684\u4ee3\u7406\u529f\u80fd\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u5728\u4f7f\u7528requests\u5e93\u65f6\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u8bf7\u6c42\u4e2d\u8bbe\u7f6e\u4ee3\u7406\u53c2\u6570\u6765\u5b9e\u73b0\u4ee3\u7406IP\u7684\u4f7f\u7528\u3002\u5177\u4f53\u800c\u8a00\uff0c\u4f60\u53ea\u9700\u5728\u8bf7\u6c42\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u5b57\u5178\uff0c\u6307\u5b9a\u4f60\u8981\u4f7f\u7528\u7684\u4ee3\u7406\u670d\u52a1\u5668\u7684\u534f\u8bae\u548cIP\u5730\u5740\u5373\u53ef\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5728Python\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u5bf9\u4ee3\u7406IP\u7684\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528REQUESTS\u5e93\u8bbe\u7f6e\u4ee3\u7406IP<\/h3>\n<\/p>\n<p><p>Requests\u5e93\u662fPython\u4e2d\u6700\u6d41\u884c\u7684HTTP\u5e93\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u7b80\u5355\u7684API\u6765\u53d1\u9001HTTP\u8bf7\u6c42\u5e76\u63a5\u6536\u54cd\u5e94\u3002\u4f7f\u7528requests\u5e93\u8bbe\u7f6e\u4ee3\u7406IP\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u4f20\u9012\u4e00\u4e2aproxies\u53c2\u6570\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5requests\u5e93<\/strong>\uff1a\u9996\u5148\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86requests\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u4ee3\u7406IP<\/strong>\uff1a\u5728\u53d1\u9001\u8bf7\u6c42\u65f6\uff0c\u901a\u8fc7proxies\u53c2\u6570\u6307\u5b9a\u4ee3\u7406\u670d\u52a1\u5668\u3002proxies\u53c2\u6570\u662f\u4e00\u4e2a\u5b57\u5178\uff0c\u952e\u4e3a\u534f\u8bae\uff08http\u6216https\uff09\uff0c\u503c\u4e3a\u4ee3\u7406\u670d\u52a1\u5668\u7684URL\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>proxies = {<\/p>\n<p>    &quot;http&quot;: &quot;http:\/\/your_proxy_ip:your_proxy_port&quot;,<\/p>\n<p>    &quot;https&quot;: &quot;https:\/\/your_proxy_ip:your_proxy_port&quot;,<\/p>\n<p>}<\/p>\n<p>response = requests.get(&quot;http:\/\/example.com&quot;, proxies=proxies)<\/p>\n<p>print(response.text)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a\u5728\u4f7f\u7528\u4ee3\u7406\u65f6\uff0c\u8bf7\u786e\u4fdd\u4ee3\u7406\u670d\u52a1\u5668\u7684IP\u548c\u7aef\u53e3\u6b63\u786e\uff0c\u5e76\u4e14\u4ee3\u7406\u670d\u52a1\u5668\u662f\u53ef\u7528\u7684\u3002\u5982\u679c\u4ee3\u7406\u670d\u52a1\u5668\u9700\u8981\u8eab\u4efd\u9a8c\u8bc1\uff0c\u4f60\u8fd8\u9700\u8981\u5728\u4ee3\u7406URL\u4e2d\u5305\u542b\u7528\u6237\u540d\u548c\u5bc6\u7801\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">proxies = {<\/p>\n<p>    &quot;http&quot;: &quot;http:\/\/username:password@your_proxy_ip:your_proxy_port&quot;,<\/p>\n<p>    &quot;https&quot;: &quot;https:\/\/username:password@your_proxy_ip:your_proxy_port&quot;,<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u4f7f\u7528URLLIB\u5e93\u8bbe\u7f6e\u4ee3\u7406IP<\/h3>\n<\/p>\n<p><p>urllib\u662fPython\u5185\u7f6e\u7684HTTP\u8bf7\u6c42\u5e93\uff0c\u867d\u7136\u529f\u80fd\u4e0d\u5982requests\u5f3a\u5927\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4ecd\u7136\u975e\u5e38\u6709\u7528\u3002urllib\u5e93\u4e5f\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u4ee3\u7406\u6765\u5b9e\u73b0IP\u4ee3\u7406\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5bfc\u5165\u6a21\u5757<\/strong>\uff1aurllib\u5e93\u662fPython\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u56e0\u6b64\u65e0\u9700\u989d\u5916\u5b89\u88c5\u3002\u4f60\u53ef\u4ee5\u76f4\u63a5\u5bfc\u5165\u76f8\u5173\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import urllib.request<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u4ee3\u7406IP<\/strong>\uff1a\u4f7f\u7528ProxyHandler\u8bbe\u7f6e\u4ee3\u7406\uff0c\u7136\u540e\u901a\u8fc7build_opener\u521b\u5efa\u4e00\u4e2aopener\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">proxy_handler = urllib.request.ProxyHandler({<\/p>\n<p>    &quot;http&quot;: &quot;http:\/\/your_proxy_ip:your_proxy_port&quot;,<\/p>\n<p>    &quot;https&quot;: &quot;https:\/\/your_proxy_ip:your_proxy_port&quot;,<\/p>\n<p>})<\/p>\n<p>opener = urllib.request.build_opener(proxy_handler)<\/p>\n<p>urllib.request.install_opener(opener)<\/p>\n<p>response = urllib.request.urlopen(&quot;http:\/\/example.com&quot;)<\/p>\n<p>print(response.read().decode(&#39;utf-8&#39;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a\u4e0erequests\u5e93\u7c7b\u4f3c\uff0c\u5728\u4f7f\u7528urllib\u8bbe\u7f6e\u4ee3\u7406\u65f6\uff0c\u4e5f\u9700\u8981\u786e\u4fdd\u4ee3\u7406\u670d\u52a1\u5668\u7684IP\u548c\u7aef\u53e3\u6b63\u786e\uff0c\u5e76\u786e\u4fdd\u4ee3\u7406\u670d\u52a1\u5668\u662f\u53ef\u7528\u7684\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u4f7f\u7528SOCKS\u5e93\u8bbe\u7f6e\u4ee3\u7406IP<\/h3>\n<\/p>\n<p><p>socks\u5e93\u5141\u8bb8\u4f60\u901a\u8fc7SOCKS\u534f\u8bae\u8bbe\u7f6e\u4ee3\u7406\uff0c\u8fd9\u5728\u9700\u8981\u66f4\u9ad8\u7ea7\u7684\u4ee3\u7406\u529f\u80fd\uff08\u5982SOCKS5\uff09\u65f6\u5c24\u5176\u6709\u7528\u3002PySocks\u662f\u4e00\u4e2a\u5e38\u7528\u7684socks\u5e93\uff0c\u5b83\u652f\u6301SOCKS4\u3001SOCKS5\u548cHTTP\u4ee3\u7406\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5PySocks\u5e93<\/strong>\uff1a\u5982\u679c\u4f60\u6253\u7b97\u4f7f\u7528socks\u5e93\uff0c\u9700\u8981\u5148\u5b89\u88c5PySocks\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install PySocks<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u914d\u7f6esocks\u4ee3\u7406<\/strong>\uff1a\u4f7f\u7528socks\u5e93\u65f6\uff0c\u9700\u8981\u901a\u8fc7socks.set_default_proxy\u51fd\u6570\u8bbe\u7f6e\u9ed8\u8ba4\u4ee3\u7406\uff0c\u7136\u540e\u4f7f\u7528socks.socksocket\u66ff\u4ee3\u5e38\u89c4\u7684socket\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import socks<\/p>\n<p>import socket<\/p>\n<p>from urllib import request<\/p>\n<p>socks.set_default_proxy(socks.SOCKS5, &quot;your_proxy_ip&quot;, your_proxy_port)<\/p>\n<p>socket.socket = socks.socksocket<\/p>\n<p>response = request.urlopen(&quot;http:\/\/example.com&quot;)<\/p>\n<p>print(response.read().decode(&#39;utf-8&#39;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a\u786e\u4fdd\u4f60\u4f7f\u7528\u7684\u662f\u652f\u6301SOCKS\u534f\u8bae\u7684\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u5e76\u786e\u8ba4IP\u548c\u7aef\u53e3\u7684\u6b63\u786e\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u4f7f\u7528THIRD-PARTY\u4ee3\u7406\u6c60\u5b9e\u73b0\u4ee3\u7406IP<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u9891\u7e41\u66f4\u6362\u4ee3\u7406IP\uff0c\u8fd9\u65f6\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u7b2c\u4e09\u65b9\u4ee3\u7406\u6c60\u5e93\uff0c\u5982<code>proxy-pool<\/code>\u3002\u8fd9\u4e9b\u5e93\u901a\u5e38\u4f1a\u81ea\u52a8\u83b7\u53d6\u548c\u7ef4\u62a4\u4e00\u7ec4\u53ef\u7528\u7684\u4ee3\u7406IP\uff0c\u65b9\u4fbf\u4f60\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5proxy-pool\u5e93<\/strong>\uff1a\u4ee5proxy-pool\u4e3a\u4f8b\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install proxy-pool<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u83b7\u53d6\u4ee3\u7406IP<\/strong>\uff1a\u901a\u8fc7proxy-pool\u5e93\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u4e00\u4e2a\u53ef\u7528\u7684\u4ee3\u7406IP\u5217\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from proxy_pool import ProxyPool<\/p>\n<p>pool = ProxyPool()<\/p>\n<p>proxy = pool.get()  # \u83b7\u53d6\u4e00\u4e2a\u53ef\u7528\u4ee3\u7406<\/p>\n<p>proxies = {<\/p>\n<p>    &quot;http&quot;: f&quot;http:\/\/{proxy}&quot;,<\/p>\n<p>    &quot;https&quot;: f&quot;https:\/\/{proxy}&quot;,<\/p>\n<p>}<\/p>\n<p>response = requests.get(&quot;http:\/\/example.com&quot;, proxies=proxies)<\/p>\n<p>print(response.text)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a\u4f7f\u7528\u4ee3\u7406\u6c60\u65f6\uff0c\u8bf7\u786e\u4fdd\u9075\u5faa\u76f8\u5173\u6cd5\u5f8b\u6cd5\u89c4\uff0c\u5e76\u6ce8\u610f\u4e0d\u8981\u5bf9\u76ee\u6807\u670d\u52a1\u5668\u9020\u6210\u4e0d\u5fc5\u8981\u7684\u8d1f\u62c5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u4ee3\u7406IP\u7684\u4f7f\u7528\u573a\u666f\u4e0e\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><h4>\u4f7f\u7528\u573a\u666f\uff1a<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7a81\u7834IP\u9650\u5236<\/strong>\uff1a\u5728\u722c\u866b\u8fc7\u7a0b\u4e2d\uff0c\u67d0\u4e9b\u7f51\u7ad9\u53ef\u80fd\u4f1a\u5bf9\u9891\u7e41\u8bf7\u6c42\u7684IP\u8fdb\u884c\u9650\u5236\uff0c\u901a\u8fc7\u4f7f\u7528\u4ee3\u7406IP\uff0c\u53ef\u4ee5\u6709\u6548\u7a81\u7834\u8fd9\u4e9b\u9650\u5236\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u63d0\u9ad8\u533f\u540d\u6027<\/strong>\uff1a\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u9690\u85cf\u771f\u5b9eIP\u4ee5\u63d0\u9ad8\u533f\u540d\u6027\uff0c\u4f7f\u7528\u4ee3\u7406IP\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8d1f\u8f7d\u5747\u8861<\/strong>\uff1a\u5728\u9ad8\u5e76\u53d1\u8bf7\u6c42\u573a\u666f\u4e0b\uff0c\u4f7f\u7528\u591a\u4e2a\u4ee3\u7406IP\u53ef\u4ee5\u6709\u6548\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\uff0c\u51cf\u8f7b\u5355\u4e2aIP\u7684\u538b\u529b\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h4>\u6ce8\u610f\u4e8b\u9879\uff1a<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5408\u6cd5\u5408\u89c4<\/strong>\uff1a\u5728\u4f7f\u7528\u4ee3\u7406IP\u65f6\uff0c\u8bf7\u786e\u4fdd\u9075\u5faa\u76f8\u5173\u6cd5\u5f8b\u6cd5\u89c4\uff0c\u4e0d\u8981\u6ee5\u7528\u4ee3\u7406IP\u8fdb\u884c\u6076\u610f\u6d3b\u52a8\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4ee3\u7406\u53ef\u7528\u6027<\/strong>\uff1a\u4ee3\u7406IP\u7684\u53ef\u7528\u6027\u53ef\u80fd\u968f\u65f6\u95f4\u53d8\u5316\u800c\u6539\u53d8\uff0c\u56e0\u6b64\u5728\u4f7f\u7528\u4ee3\u7406\u65f6\uff0c\u9700\u8981\u5b9a\u671f\u68c0\u67e5\u4ee3\u7406\u7684\u53ef\u7528\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4ee3\u7406\u901f\u5ea6<\/strong>\uff1a\u4f7f\u7528\u4ee3\u7406IP\u53ef\u80fd\u4f1a\u5f71\u54cd\u8bf7\u6c42\u901f\u5ea6\uff0c\u56e0\u6b64\u5728\u9009\u62e9\u4ee3\u7406\u65f6\uff0c\u9700\u8981\u5e73\u8861\u533f\u540d\u6027\u548c\u901f\u5ea6\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u5728Python\u4e2d\u7075\u6d3b\u5730\u4f7f\u7528\u4ee3\u7406IP\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u573a\u666f\u7684\u9700\u6c42\u3002\u65e0\u8bba\u662f\u4f7f\u7528requests\u5e93\u3001urllib\u5e93\u8fd8\u662fsocks\u5e93\uff0cPython\u90fd\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u652f\u6301\uff0c\u4f7f\u4f60\u80fd\u591f\u8f7b\u677e\u5b9e\u73b0\u4ee3\u7406IP\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bbe\u7f6e\u4ee3\u7406IP\u4ee5\u63d0\u5347\u7f51\u7edc\u8bf7\u6c42\u7684\u9690\u79c1\u6027\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>requests<\/code>\u5e93\u6765\u8bbe\u7f6e\u4ee3\u7406IP\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86<code>requests<\/code>\u5e93\u3002\u4f7f\u7528\u4ee3\u7406\u65f6\uff0c\u9700\u8981\u5728\u8bf7\u6c42\u4e2d\u5305\u542b\u4ee3\u7406\u7684\u5730\u5740\u3002\u4f8b\u5982\uff0c\u4f7f\u7528HTTP\u4ee3\u7406\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import requests\n\nproxies = {\n    &quot;http&quot;: &quot;http:\/\/your_proxy_ip:port&quot;,\n    &quot;https&quot;: &quot;http:\/\/your_proxy_ip:port&quot;,\n}\n\nresponse = requests.get(&quot;http:\/\/example.com&quot;, proxies=proxies)\nprint(response.text)\n<\/code><\/pre>\n<p>\u786e\u4fdd\u5c06<code>your_proxy_ip<\/code>\u548c<code>port<\/code>\u66ff\u6362\u4e3a\u5b9e\u9645\u7684\u4ee3\u7406\u5730\u5740\u548c\u7aef\u53e3\u53f7\u3002<\/p>\n<p><strong>\u4f7f\u7528\u4ee3\u7406IP\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4e8b\u9879\uff1f<\/strong><br \/>\u4f7f\u7528\u4ee3\u7406IP\u53ef\u80fd\u4f1a\u5f71\u54cd\u8bf7\u6c42\u7684\u901f\u5ea6\u548c\u7a33\u5b9a\u6027\uff0c\u5c24\u5176\u662f\u5f53\u4ee3\u7406\u670d\u52a1\u5668\u8d1f\u8f7d\u8f83\u9ad8\u65f6\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u4f7f\u7528\u7684\u4ee3\u7406IP\u662f\u53ef\u9760\u7684\uff0c\u4ee5\u907f\u514d\u88ab\u5c01\u9501\u6216\u9650\u5236\u3002\u8fd8\u5e94\u6ce8\u610f\uff0c\u67d0\u4e9b\u7f51\u7ad9\u53ef\u80fd\u4f1a\u68c0\u6d4b\u5230\u4ee3\u7406\u8bf7\u6c42\u5e76\u91c7\u53d6\u63aa\u65bd\uff0c\u56e0\u6b64\u4f7f\u7528\u4ee3\u7406\u65f6\u8981\u4fdd\u6301\u8c28\u614e\uff0c\u9075\u5b88\u76f8\u5173\u6cd5\u5f8b\u6cd5\u89c4\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709Python\u5e93\u53ef\u4ee5\u7b80\u5316\u4ee3\u7406IP\u7684\u4f7f\u7528\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u9664\u4e86<code>requests<\/code>\u5e93\uff0c<code>httpx<\/code>\u548c<code>urllib<\/code>\u7b49\u5e93\u4e5f\u652f\u6301\u4ee3\u7406IP\u7684\u8bbe\u7f6e\u3002<code>httpx<\/code>\u5e93\u63d0\u4f9b\u4e86\u5f02\u6b65\u8bf7\u6c42\u7684\u529f\u80fd\uff0c\u9002\u5408\u9700\u8981\u9ad8\u5e76\u53d1\u7684\u573a\u666f\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528<code>httpx<\/code>\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">import httpx\n\nproxies = {\n    &quot;http:\/\/&quot;: &quot;http:\/\/your_proxy_ip:port&quot;,\n    &quot;https:\/\/&quot;: &quot;http:\/\/your_proxy_ip:port&quot;,\n}\n\nasync with httpx.AsyncClient(proxies=proxies) as client:\n    response = aw<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>t client.get(&quot;http:\/\/example.com&quot;)\n    print(response.text)\n<\/code><\/pre>\n<p>\u9009\u62e9\u5408\u9002\u7684\u5e93\u53ef\u4ee5\u8ba9\u4ee3\u7406IP\u7684\u4f7f\u7528\u66f4\u52a0\u9ad8\u6548\u548c\u4fbf\u6377\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u4f7f\u7528\u4ee3\u7406IP\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5982\u4f7f\u7528requests\u5e93\u3001urllib\u5e93\u3001socks\u5e93\u7b49\u3002\u8fd9 [&hellip;]","protected":false},"author":3,"featured_media":993176,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/993170"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=993170"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/993170\/revisions"}],"predecessor-version":[{"id":993178,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/993170\/revisions\/993178"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/993176"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=993170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=993170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=993170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}