You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何读取IP2Proxy™ LITE数据库IP地址?Python/PowerShell方法及字段解析

IP2Proxy™ LITE CSV数据库处理指南

数据库前两列含义

IP2Proxy™ LITE版CSV的前两列是IP范围的核心定义:

  • 第一列(ip_from):IP段的起始地址,以纯数字格式存储(即IPv4地址转换后的32位无符号整数)
  • 第二列(ip_to):IP段的结束地址,同样是纯数字的IPv4整数形式
    这两列共同划定了一个连续的IP区间,后续列的代理属性(如代理类型、所属地区等)均适用于该区间内的所有IP。

Python 读取并转换IP格式

使用Python的csv模块读取文件,结合socket和struct模块将纯数字IP转为标准点分十进制格式:

import csv
import socket
import struct

def int_to_ip(ip_int):
    # 把整数IP转为点分十进制字符串
    return socket.inet_ntoa(struct.pack(">I", ip_int))

# 替换为你的CSV文件路径
csv_path = "IP2PROXY-LITE-PX1.CSV"
with open(csv_path, "r", encoding="utf-8") as f:
    reader = csv.reader(f)
    # 若CSV有表头,取消下方注释跳过表头
    # next(reader)
    for row in reader:
        # 提取前两列的整数IP并转换
        start_ip = int_to_ip(int(row[0]))
        end_ip = int_to_ip(int(row[1]))
        print(f"IP区间: {start_ip} - {end_ip}")
        # 此处可添加后续列的处理逻辑

PowerShell 读取并转换IP格式

利用PowerShell的Import-Csv读取文件,通过.NET类[System.Net.IPAddress]完成格式转换:

# 替换为你的CSV文件路径
$csvPath = "IP2PROXY-LITE-PX1.CSV"
# 因LITE版CSV无表头,手动指定列名(可根据实际列数调整)
$csvData = Import-Csv -Path $csvPath -Header "ip_from", "ip_to", "proxy_type", "country_code", "country_name", "region_name", "city_name", "isp", "domain", "usage_type", "asn", "as_name", "last_seen", "threat", "provider"

foreach ($row in $csvData) {
    # 转换整数IP为标准格式
    $startIp = ([System.Net.IPAddress][long]$row.ip_from).IPAddressToString
    $endIp = ([System.Net.IPAddress][long]$row.ip_to).IPAddressToString
    Write-Host "IP区间: $startIp - $endIp"
    # 此处可添加后续列的处理逻辑
}

内容的提问来源于stack exchange,提问作者Naveen Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 06:20:30