一 需求
如果业务有需求,判断IP是否来自境外。
有一些方案:
1 使用第三方的接口:比如IP138或者提供IP解析的云厂商等。
优点: 接口简单,不关注实现。
缺点:付费。
我看收费每月5元。
2 自己实现。
你可以搜一下,大概率会搜到官方IP段的一个方案。
相关知识:
RIR (Regional Internet Registry)地区性 Internet 注册机构,负责将IP地址块分配给ISP的多家国际组织之一。
RIR
现全球有5大RIR机构
1.RIPE(Reseaux IP Europeans)欧洲IP地址注册中心——服务于欧洲、中东地区和中亚地区;
2.LACNIC(Lation American and Caribbean Internet Address Registry)拉丁美洲和加勒比海Internet地址注册中心——服务于中美、南美以及加勒比海地区;
3.ARIN(American Registry for Internet Numvers)美国Internet编号注册中心——服务于北美地区和部分加勒比海地区;
4.AFRINIC(Africa Network Information Centre)非洲网络信息中心——服务于非洲地区;
5.APNIC(Asia Pacific Network Information Centre)亚太地址网络信息中心——服务于亚洲和太平洋地区的国家。
如果你关注:DNS反向解析即由IP地址反查域名信息,除了常用dig工具反查外,也需要根据IP查询对应的ASN(Autonomous System Number)是为每个大型网络分配的编号,该编号全球唯一。通过查询IP地址隶属的ASN编号,可以了解该IP地址隶属的网络运营商,以及大致的地址位置。Nmap提供asn-query脚本来查询IP地址的ASN编号,并给出BGP、区域、起始和节点编号等信息。
下面展开说一下,业务比较狭窄,请我吃雪糕的可以支持下。
二 关于IP段
apnic|AU|asn|140730|1|20200616|allocated apnic|CN|asn|140731|1|20200616|allocated apnic|PK|asn|140732|1|20200616|allocated apnic|HK|asn|140733|1|20200616|allocated apnic|PH|asn|140734|1|20200616|allocated apnic|AU|asn|140735|1|20200618|allocated apnic|AU|asn|140736|1|20200617|allocated apnic|VN|asn|140737|100|20200617|allocated apnic|MY|asn|140837|1|20200617|allocated apnic|CN|asn|140838|1|20200617|allocated apnic|NZ|asn|140839|1|20200618|allocated apnic|NZ|asn|140840|1|20200618|allocated apnic|HK|asn|140841|1|20200619|allocated apnic|CN|asn|140842|1|20200619|allocated apnic|BD|asn|140843|1|20200619|allocated apnic|NZ|asn|140844|1|20200619|allocated apnic|SG|asn|140845|1|20200619|allocated apnic|CN|asn|140846|1|20200619|allocated apnic|BD|asn|140847|1|20200619|allocated apnic|CN|asn|140848|1|20200620|allocated apnic|BD|asn|140849|1|20200620|allocated apnic|BD|asn|140850|1|20200622|allocated apnic|NZ|asn|140851|1|20200623|allocated apnic|CN|asn|140852|1|20200623|allocated apnic|CN|asn|140853|11|20200624|allocated apnic|BD|asn|140864|1|20200624|allocated apnic|BD|asn|140865|1|20200624|allocated apnic|MY|asn|140866|1|20200625|allocated apnic|TH|asn|140867|1|20200625|allocated apnic|JP|asn|140868|1|20200626|allocated apnic|IN|asn|140869|1|20200626|allocated apnic|NZ|asn|140870|1|20200629|allocated apnic|IN|asn|140871|1|20200629|allocated apnic|NZ|asn|140872|1|20200629|allocated apnic|CN|asn|140873|1|20200629|allocated apnic|NZ|asn|140874|1|20200629|allocated apnic|HK|asn|140875|1|20200630|allocated apnic|AU|asn|140876|1|20200630|allocated apnic|BD|asn|140877|1|20200630|allocated apnic|PH|asn|140878|1|20200630|allocated apnic|BD|asn|140879|1|20200630|allocated apnic|AU|asn|140880|1|20200630|allocated apnic|CN|asn|140881|1|20200701|allocated apnic|HK|asn|140882|1|20200701|allocated apnic|HK|asn|140883|1|20200701|allocated apnic|AU|asn|140884|1|20200701|allocated apnic|AU|ipv4|1.0.0.0|256|20110811|assigned apnic|CN|ipv4|1.0.1.0|256|20110414|allocated apnic|CN|ipv4|1.0.2.0|512|20110414|allocated apnic|AU|ipv4|1.0.4.0|1024|20110412|allocated apnic|CN|ipv4|1.0.8.0|2048|20110412|allocated apnic|JP|ipv4|1.0.16.0|4096|20110412|allocated apnic|CN|ipv4|1.0.32.0|8192|20110412|allocated apnic|JP|ipv4|1.0.64.0|16384|20110412|allocated apnic|TH|ipv4|1.0.128.0|32768|20110408|allocated apnic|CN|ipv4|1.1.0.0|256|20110414|allocated apnic|AU|ipv4|1.1.1.0|256|20110811|assigned apnic|CN|ipv4|1.1.2.0|512|20110414|allocated apnic|CN|ipv4|1.1.4.0|1024|20110414|allocated apnic|CN|ipv4|1.1.8.0|256|20110412|allocated apnic|CN|ipv4|1.1.9.0|256|20110412|allocated apnic|CN|ipv4|1.1.10.0|512|20110412|allocated apnic|CN|ipv4|1.1.12.0|1024|20110412|allocated apnic|CN|ipv4|1.1.16.0|4096|20110412|allocated apnic|CN|ipv4|1.1.32.0|8192|20110412|allocated apnic|JP|ipv4|1.1.64.0|16384|20110412|allocated apnic|TH|ipv4|1.1.128.0|32768|20110408|allocated apnic|CN|ipv4|1.2.0.0|512|20110414|allocated apnic|CN|ipv4|1.2.2.0|256|20110331|assigned apnic|AU|ipv4|1.2.3.0|256|20110811|assigned apnic|CN|ipv4|1.2.4.0|256|20110414|allocated apnic|CN|ipv4|1.2.5.0|256|20110414|allocated apnic|CN|ipv4|1.2.6.0|512|20110414|allocated apnic|CN|ipv4|1.2.8.0|256|20110412|assigned apnic|CN|ipv4|1.2.9.0|256|20110412|allocated apnic|CN|ipv4|1.2.10.0|512|20110412|allocated apnic|CN|ipv4|1.2.12.0|1024|20110412|allocated apnic|CN|ipv4|1.2.16.0|4096|20110412|allocated apnic|CN|ipv4|1.2.32.0|8192|201104