ASN(Autonomous System Number)是为每个大型网络分配的编号,该编号全球唯一。通过查询IP地址隶属的ASN编号,可以了解该IP地址隶属的网络运营商,以及大致的地址位置。Nmap提供asn-query脚本来查询IP地址的ASN编号,并给出BGP、区域、起始和节点编号等信息。
文件下载的话大伙网上找资源吧!我当时也是自己找的!大家可以在csdn上搜索,这些资源肯定都有。
def geoIp(ip):
"""
获取ip详细信息方法
"""
import pygeoip
import geoip2.database
gi = pygeoip.GeoIP('GeoLiteCity.dat')
giv6 = pygeoip.GeoIP('GeoLiteCityv6.dat')
geo_city = geoip2.database.Reader('GeoLite2-City.mmdb')
geo_asn = geoip2.database.Reader('GeoLite2-ASN.mmdb')
geo_isp = geoip2.database.Reader('GeoIP2-ISP.mmdb')
response = geo_city.city(ip)
response_asn = geo_asn.asn(ip)
response_isp = geo_isp.isp(ip)
rec_ipv6 = giv6.record_by_addr(ip)
rec_ipv4 = gi.record_by_addr(ip)
country_e_name = response.country.name # 国家-英文名
country_c_name = response.country.names.get('zh-CN') # 国家-中文名
city_e = response.subdivisions
city_e_name = city_e[0].names.get('en') # 城市-英文名
city_c_name = city_e[0].names.get('zh-CN', '') # 城市-中文名
continent_e = response.continent.code # 洲、大陆(如亚洲、欧洲)-英文
asn_code = response_asn.autonomous_system_number # asn编码
asn_cn = response_asn.autonomous_system_organization # asn中文地址
operator = response_isp.isp # ip运营商英文名称
city = rec_ipv6['city'] # 城市
region = rec_ipv6['region_code'] # 地区
country = rec_ipv6['country_name'] # 国家
country_code = rec_ipv6['country_code'] # 国家代码
area_code = rec_ipv6['area_code'] # 区域代码
continent = rec_ipv6['continent'] # 洲、大陆(如亚洲、欧洲)
long = rec_ipv6['longitude'] # 经度
lat = rec_ipv6['latitude'] # 纬度
city = rec_ipv4['city'] # 城市
region = rec_ipv4['region_code'] # 地区
country = rec_ipv4['country_name'] # 国家
country_code = rec_ipv4['country_code'] # 国家代码
area_code = rec_ipv4['area_code'] # 区域代码
continent = rec_ipv4['continent'] # 洲、大陆(如亚洲、欧洲)
long = rec_ipv4['longitude'] # 经度
lat = rec_ipv4['latitude'] # 纬度
使用起来就像字典一样。新手可以多输出看下结果!
ASN是为大型网络分配的全球唯一编号,查询IP地址隶属的ASN编号,可了解其网络运营商和大致位置。Nmap提供asn - query脚本用于查询,还会给出BGP、区域等信息,新手可多输出查看结果。

被折叠的 条评论
为什么被折叠?



