【快代理API】查询隧道代理当前IP

本文介绍了一种通过Kuaidaili API实时查询隧道代理当前IP的方法,适用于换IP周期大于等于1分钟的订单。文章提供了Python代码示例,演示了如何使用API查询并打印当前代理IP。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

接口描述

  • https://tps.kdlapi.com/api/tpscurrentip 接口地址
  • 实时查询隧道代理当前IP
  • 仅支持换IP周期>=1分钟的隧道代理订单
  • 注意要实际使用才能查询到当前IP

返回结果

返回隧道当前IP
在这里插入图片描述

参数说明

在这里插入图片描述

必填参数
  1. orderid 订单号
  2. signature API Key

获取订单号和API Key教程

代码样例

import requests

# 使用隧道代理
# 隧道服务器
tunnel_host = "tps176.kdlapi.com"
tunnel_port = 15818

# 隧道id和密码
tid = "t18538132507140"
password = "4zdldwy7"

proxies = {
    "http": "http://%s:%s@%s:%s/" % (tid, password, tunnel_host, tunnel_port),
    "https": "http://%s:%s@%s:%s/" % (tid, password, tunnel_host, tunnel_port)
}

r = requests.get("https://dev.kdlapi.com/testproxy", proxies=proxies)

# API接口
api_url = "https://tps.kdlapi.com/api/tpscurrentip"

# 订单号跟API Key
orderid = 918538132507097
api_key = "azx0jv2f1r9ytsmzuxskvrf9rp01vcea"

# 参数
params = {
        "orderid": orderid,
        "signature": api_key,
        }

res = requests.get(api_url, params=params)
print(res.content)

运行结果,返回当前代理
在这里插入图片描述

进阶学习

### 终端代理设置后无法连接到 GitHub 的解决方案 当终端设置了代理但仍无法连接到 GitHub 时,可能涉及多个方面的原因。以下是详细的分析和解决方法: #### 1. **HTTPS 连接通过代理** 对于显式代理的 HTTPS 请求,客户端需要向代理发送 `CONNECT` 方法来建立隧道[^1]。如果代理配置不正确或者未允许特定目标域名(如 github.com),则可能导致连接失败。 可以通过以下方式验证并修复: - 确认代理支持 `CONNECT` 方法,并且已开放对 github.com 的访问。 - 使用命令测试代理是否正常工作: ```bash curl -x http://proxy_host:proxy_port https://github.com --connect-timeout 5 ``` #### 2. **DNS 解析问题** 有时即使代理设置无误,也可能因为 DNS 解析错误而无法连接到目标站点。可以尝试手动指定 IP 地址或调整 `/etc/hosts` 文件中的条目[^2]。 例如,在本地 hosts 文件中加入类似如下记录以强制解析: ```bash echo "140.82.118.3 github.com" | sudo tee -a /etc/hosts ``` 注意替换上述 IP (`140.82.118.3`) 为当前有效的 GitHub 主机地址。 #### 3. **Git 配置全局代理** 确保 Git 工具本身已经正确定义了网络代理参数。执行下面指令完成相应设定: ```bash git config --global http.proxy http://proxy_user:proxy_password@proxy_server:port git config --global https.proxy http://proxy_user:proxy_password@proxy_server:port ``` 取消代理可运行: ```bash git config --global --unset http.proxy git config --global --unset https.proxy ``` #### 4. **防火墙与安全组规则** 检查所在环境是否存在额外的安全策略阻止对外部资源的请求。比如企业内部网络通常会部署严格 ACL 或者 Web Application Firewall (WAF),它们可能会拦截未经许可的目的地流量。 联系 IT 支持团队确认是否有针对 github.com 设置例外白名单。 --- ```python import requests proxies = { 'http': 'http://your_proxy_address:port', 'https': 'http://your_proxy_address:port' } try: response = requests.get('https://api.github.com', proxies=proxies, timeout=10) print(response.status_code) except Exception as e: print(f'Error occurred: {e}') ``` 此脚本可用于进一步诊断 Python 下基于 Requests 库发起带代理的 HTTP(S) 调用情况。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值