如何为 OpenClaw 开发一个代理 IP 查询技能?

发布时间:2026-03-19  阅读:830

10 分钟教你为 OpenClaw 开发一个代理 IP 查询技能,让你的 AI 助手可以实时查询 IP 信息、检测 IP 质量、管理代理 IP 池。

OpenClaw 代理 IP 查询技能


问题 答案
需要什么基础? 基础 Python 知识
开发时间? 10-30 分钟
能做什么? IP 查询、质量检测、IP 池管理
难不难? 有教程,跟着做就行
收益? 提升工作效率,可复用

为什么需要代理 IP 查询技能?

使用场景

场景 需求
爬虫采集 实时检测 IP 可用性
跨境电商 多账号 IP 管理
数据采集 IP 池质量监控
游戏工作室 IP 稳定性检测

痛点

  • 手动查询 IP 效率低
  • IP 质量无法实时监控
  • 多 IP 管理混乱
  • 被封 IP 不能及时发现

技能功能设计

核心功能

功能 说明
IP 查询 查询 IP 归属地、运营商
质量检测 检测 IP 可用性、响应速度
IP 池管理 添加、删除、批量检测
自动告警 IP 被封自动通知

技术架构

OpenClaw 消息
        ↓
   代理 IP 查询技能
        ↓
   悟空代理 API
        ↓
   返回 IP 信息

开发步骤(10 分钟完成)

第一步:创建技能目录

# 进入技能目录
cd ~/.openclaw/skills/

# 创建技能文件夹
mkdir -p proxy-ip-checker
cd proxy-ip-checker

第二步:创建 SKILL.md 文件

touch SKILL.md

编辑 SKILL.md

---
name: proxy-ip-checker
description: 代理 IP 查询和检测技能
---

## 功能

查询代理 IP 信息、检测 IP 质量、管理 IP 池。

## 使用方法

1. 查询 IP:"查询 IP 123.45.67.89"
2. 检测 IP:"检测这个 IP 能不能用"
3. 批量检测:"检测 IP 池里所有 IP"

## API 配置

- API 地址:https://www.wukongdaili.com/api/
- 需要订单 ID(从悟空代理官网获取)

第三步:创建 Python 脚本

touch ip_checker.py

编辑 ip_checker.py

import requests
import json
from datetime import datetime

class ProxyIPChecker:
    """代理 IP 查询和检测"""

    def __init__(self, order_id):
        self.order_id = order_id
        self.api_url = "https://www.wukongdaili.com/api"

    def get_proxy_ip(self, num=1):
        """获取代理 IP"""
        url = f"{self.api_url}/get_proxy"
        params = {
            "order_id": self.order_id,
            "num": num,
            "format": "json"
        }
        response = requests.get(url, params=params)
        return response.json()

    def check_ip_quality(self, ip, port):
        """检测 IP 质量"""
        proxies = {
            'http': f"http://{ip}:{port}",
            'https': f"http://{ip}:{port}"
        }

        try:
            # 测试响应时间
            start_time = datetime.now()
            response = requests.get(
                "https://www.wukongdaili.com",
                proxies=proxies,
                timeout=10
            )
            end_time = datetime.now()

            # 计算响应时间
            response_time = (end_time - start_time).total_seconds() * 1000

            return {
                "status": "success",
                "ip": ip,
                "port": port,
                "response_time": f"{response_time:.0f}ms",
                "status_code": response.status_code
            }
        except Exception as e:
            return {
                "status": "failed",
                "ip": ip,
                "port": port,
                "error": str(e)
            }

    def batch_check(self, ip_list):
        """批量检测 IP"""
        results = []
        for ip_info in ip_list:
            result = self.check_ip_quality(ip_info['ip'], ip_info['port'])
            results.append(result)
        return results

# 使用示例
if __name__ == "__main__":
    checker = ProxyIPChecker(order_id="你的订单 ID")

    # 获取 IP
    ip_data = checker.get_proxy_ip(num=5)
    print(f"获取到 {len(ip_data['data'])} 个 IP")

    # 批量检测
    results = checker.batch_check(ip_data['data'])
    for result in results:
        print(f"IP: {result['ip']}:{result['port']} - {result['status']}")

第四步:配置技能

编辑 ~/.openclaw/openclaw.json

{
  "skills": {
    "entries": {
      "proxy-ip-checker": {
        "enabled": true,
        "env": {
          "WUKONG_ORDER_ID": "你的订单 ID"
        }
      }
    }
  }
}

第五步:测试技能

# 重启 OpenClaw
openclaw gateway restart

# 在聊天应用里测试
"查询我的代理 IP"
"检测 IP 质量"

进阶功能

1. IP 归属地查询

def get_ip_location(self, ip):
    """查询 IP 归属地"""
    url = f"http://ip-api.com/json/{ip}"
    response = requests.get(url)
    data = response.json()

    return {
        "country": data.get('country', 'Unknown'),
        "region": data.get('regionName', 'Unknown'),
        "city": data.get('city', 'Unknown'),
        "isp": data.get('isp', 'Unknown')
    }

2. IP 池管理

class IPPoolManager:
    """IP 池管理"""

    def __init__(self):
        self.ip_pool = []

    def add_ip(self, ip, port):
        """添加 IP 到池"""
        self.ip_pool.append({
            "ip": ip,
            "port": port,
            "added_time": datetime.now(),
            "status": "active"
        })

    def remove_ip(self, ip):
        """移除 IP"""
        self.ip_pool = [p for p in self.ip_pool if p['ip'] != ip]

    def get_available_ips(self, num=1):
        """获取可用 IP"""
        available = [p for p in self.ip_pool if p['status'] == 'active']
        return available[:num]

3. 自动告警

def send_alert(self, message):
    """发送告警通知"""
    # 可以通过微信/钉钉/邮件发送
    alert_message = f"【IP 告警】{message}"
    # 调用通知 API
    print(alert_message)

常见问题

Q1: 订单 ID 从哪里获取?

登录悟空代理官网,在用户中心可以查看订单 ID。

Q2: 技能不生效怎么办?

  1. 检查 SKILL.md 格式是否正确
  2. 检查 openclaw.json 配置
  3. 重启 OpenClaw 网关

Q3: 如何调试技能?

# 查看 OpenClaw 日志
openclaw logs --follow

Q4: 可以查询其他平台的 IP 吗?

可以,修改 API 地址和参数即可。

Q5: 技能可以分享吗?

可以,发布到 ClawHub 技能市场。


技能优化建议

1. 添加缓存

from functools import lru_cache

@lru_cache(maxsize=100)
def cached_ip_check(ip, port):
    """缓存 IP 检测结果"""
    return checker.check_ip_quality(ip, port)

2. 并发检测

from concurrent.futures import ThreadPoolExecutor

def concurrent_check(self, ip_list, max_workers=10):
    """并发检测 IP"""
    with ThreadPoolExecutor(max_workers=max_workers) as executor:
        results = list(executor.map(
            lambda x: self.check_ip_quality(x['ip'], x['port']),
            ip_list
        ))
    return results

3. 持久化存储

import sqlite3

def save_to_db(self, ip, result):
    """保存检测结果到数据库"""
    conn = sqlite3.connect('ip_check.db')
    cursor = conn.cursor()
    cursor.execute(
        "INSERT INTO ip_checks (ip, port, result, time) VALUES (?, ?, ?, ?)",
        (ip['ip'], ip['port'], json.dumps(result), datetime.now())
    )
    conn.commit()
    conn.close()

总结

开发一个 OpenClaw 代理 IP 查询技能:

  • 时间:10-30 分钟
  • 难度:入门级
  • 收益:自动化 IP 管理,提升效率

核心步骤:

  1. 创建技能目录
  2. 编写 SKILL.md
  3. 实现 Python 脚本
  4. 配置并测试

下一步:

  • 发布到 ClawHub
  • 添加更多功能
  • 分享给社区

本文由悟空代理原创,转载请注明出处。

想学习更多 OpenClaw 技能开发?关注我们,后续教程持续更新。

悟空代理 - 千万住宅 IP 资源赋能大数据

悟空代理注册送ip
免费试用

客服

在线客服:

:3329077489

:18328351249 / 13316588914

:service@wukongdaili.com

售后客服微信二维码 售后客服

技术客服微信二维码 技术客服