ASN 数据库 记录了 自治系统号(ASN) 与 IP 地址段(IPv4 / IPv6) 的映射关系。 通过它,可以判断某个 IP 属于哪家运营商/云厂商/机构,用于 代理分流、网络分析、路由优化、安全风控 等场景。 与 GeoIP 不同,ASN 数据通常来自 BGP 路由公告,更贴近网络实际归属。
什么是 ASN?
ASN(Autonomous System Number) 是分配给独立自治网络的编号。每个 ASN 代表一个由组织统一管理、对外可路由的网络域。 例如:中国电信(AS4134)、中国移动(AS9808)、中国教育网(AS4538)等。
把 ASN 理解为“网络身份证”:通过 ASN,我们能快速识别 IP 的上游网络、运营商或云厂商归属。
ASN 数据库能做什么?
- 判断 IP 归属的网络或组织(识别运营商、云厂商、院校等)。
- 按 ASN 精准分流(如境内/境外、三大运营商、特定云厂商)。
- 网络优化:基于 ASN 做路由偏好、节点调度、 QoS 策略。
- 安全分析:溯源异常访问、识别“云代理段/IDC 段/住宅段”。
数据结构(列说明)
两张表结构保持一致:
start_ip:起始 IP(IPv4/IPv6)。end_ip:结束 IP(IPv4/IPv6)。asn:自治系统号(整数)。country_code:国家/地区代码(如US、CN)。organization:组织/公司/网络名称。
数据库表名:asn_ipv4_prefixes、asn_ipv6_prefixes。
在线下载
支持三种输出格式:JSON (.gz)、CSV (.gz)、SQL (.gz),分别覆盖 IPv4 与 IPv6。
| 来源 | 类型 | 格式 | 下载 | 说明 |
|---|---|---|---|---|
| IPIN | IPv6 | JSON (.gz) | ASN → IPv6 前缀映射,JSON 数组,适合程序处理。 | |
| IPIN | IPv6 | CSV (.gz) | 标准逗号分隔,含表头,适合表格/ETL。 | |
| IPIN | IPv6 | SQL (.gz) | 包含建表与 INSERT 语句,适合直接导入 MySQL。 | |
| IPIN | IPv4 | JSON (.gz) | ASN → IPv4 前缀映射,JSON 数组,适合程序处理。 | |
| IPIN | IPv4 | CSV (.gz) | 标准逗号分隔,含表头,适合表格/ETL。 | |
| IPIN | IPv4 | SQL (.gz) | 包含建表与 INSERT 语句,适合直接导入 MySQL。 |
注:所有下载均为 .gz 压缩。下载后可 gunzip 解压或直接流式处理。
命令行快速下载
curl
# IPv6 JSON
curl -fL -OJ 'https://ipin.io/download/export?type=ipv6&format=json'
# IPv6 CSV
curl -fL -OJ 'https://ipin.io/download/export?type=ipv6&format=csv'
# IPv6 SQL
curl -fL -OJ 'https://ipin.io/download/export?type=ipv6&format=sql'
# IPv4 JSON
curl -fL -OJ 'https://ipin.io/download/export?type=ipv4&format=json'
# IPv4 CSV
curl -fL -OJ 'https://ipin.io/download/export?type=ipv4&format=csv'
# IPv4 SQL
curl -fL -OJ 'https://ipin.io/download/export?type=ipv4&format=sql'
wget
# 自动采用服务端文件名(--content-disposition)
# IPv6
wget --content-disposition 'https://ipin.io/download/export?type=ipv6&format=json'
wget --content-disposition 'https://ipin.io/download/export?type=ipv6&format=csv'
wget --content-disposition 'https://ipin.io/download/export?type=ipv6&format=sql'
# IPv4
wget --content-disposition 'https://ipin.io/download/export?type=ipv4&format=json'
wget --content-disposition 'https://ipin.io/download/export?type=ipv4&format=csv'
wget --content-disposition 'https://ipin.io/download/export?type=ipv4&format=sql'
# 指定保存名 + 断点续传
wget -c -O asn_ipv6_prefixes.json.gz 'https://ipin.io/download/export?type=ipv6&format=json'
wget -c -O asn_ipv6_prefixes.csv.gz 'https://ipin.io/download/export?type=ipv6&format=csv'
wget -c -O asn_ipv6_prefixes.sql.gz 'https://ipin.io/download/export?type=ipv6&format=sql'
wget -c -O asn_ipv4_prefixes.json.gz 'https://ipin.io/download/export?type=ipv4&format=json'
wget -c -O asn_ipv4_prefixes.csv.gz 'https://ipin.io/download/export?type=ipv4&format=csv'
wget -c -O asn_ipv4_prefixes.sql.gz 'https://ipin.io/download/export?type=ipv4&format=sql'
aria2c(多线程高速下载)
# IPv6
aria2c -x16 -s16 -k1M -o asn_ipv6_prefixes.json.gz 'https://ipin.io/download/export?type=ipv6&format=json'
aria2c -x16 -s16 -k1M -o asn_ipv6_prefixes.csv.gz 'https://ipin.io/download/export?type=ipv6&format=csv'
aria2c -x16 -s16 -k1M -o asn_ipv6_prefixes.sql.gz 'https://ipin.io/download/export?type=ipv6&format=sql'
# IPv4
aria2c -x16 -s16 -k1M -o asn_ipv4_prefixes.json.gz 'https://ipin.io/download/export?type=ipv4&format=json'
aria2c -x16 -s16 -k1M -o asn_ipv4_prefixes.csv.gz 'https://ipin.io/download/export?type=ipv4&format=csv'
aria2c -x16 -s16 -k1M -o asn_ipv4_prefixes.sql.gz 'https://ipin.io/download/export?type=ipv4&format=sql'
PowerShell
# IPv6
Invoke-WebRequest -Uri "https://ipin.io/download/export?type=ipv6&format=json" -OutFile "asn_ipv6_prefixes.json.gz"
Invoke-WebRequest -Uri "https://ipin.io/download/export?type=ipv6&format=csv" -OutFile "asn_ipv6_prefixes.csv.gz"
Invoke-WebRequest -Uri "https://ipin.io/download/export?type=ipv6&format=sql" -OutFile "asn_ipv6_prefixes.sql.gz"
# IPv4
Invoke-WebRequest -Uri "https://ipin.io/download/export?type=ipv4&format=json" -OutFile "asn_ipv4_prefixes.json.gz"
Invoke-WebRequest -Uri "https://ipin.io/download/export?type=ipv4&format=csv" -OutFile "asn_ipv4_prefixes.csv.gz"
Invoke-WebRequest -Uri "https://ipin.io/download/export?type=ipv4&format=sql" -OutFile "asn_ipv4_prefixes.sql.gz"
提示:下载得到的是 .gz 压缩文件,可使用 gunzip 或解压工具进行解压;也可在程序中直接以流方式处理。
如何使用(快速上手)
- 下载并解压 JSON / CSV / SQL 文件(或直接对解压流处理)。
- 导入数据库或加载到你的程序内存模型。
- 按 ASN/组织/国家做分流策略或安全策略(如路由优选/黑白名单)。
- 建立定时任务(如每日/每周)自动更新。
格式说明
JSON
数组形式,每项包含 start_ip、end_ip、asn、country_code、organization。
CSV
首行表头;字段含逗号或双引号时已按 RFC 4180 进行转义。
SQL
包含建表与批量 INSERT 语句,适合 MySQL 直接导入。
补充说明
数据基于 BGP 路由与公共注册信息汇总。若只需中国大陆 ASN,可参考 bgp.he.net/country/CN。
常见问题(FAQ)
- 为什么 CSV 有时比 JSON 小/大? 字符串转义与字段冗余导致;两者信息一致,按你的处理链选择。
- 能做增量更新吗? 目前导出为全量,建议用计划任务覆盖导入。
- 下载失败或超时? 使用上方 curl/wget/aria2c,并确保网络允许大文件下载;服务器端已流式压缩输出,适合大表。