mirror of
https://github.com/shmilylty/OneForAll.git
synced 2026-08-26 04:47:48 +08:00
1.优化ip2region地址查询
2.增加ISP字段 3.移除ip2location地址查询
This commit is contained in:
+8
-8
@@ -78,8 +78,8 @@ class Database(object):
|
||||
f'cidr text,'
|
||||
f'asn text,'
|
||||
f'org text,'
|
||||
f'ip2region text,'
|
||||
f'ip2location text,'
|
||||
f'addr text,'
|
||||
f'isp text,'
|
||||
f'resolver text,'
|
||||
f'module text,'
|
||||
f'source text,'
|
||||
@@ -103,13 +103,13 @@ class Database(object):
|
||||
f'insert into "{table_name}" '
|
||||
f'(id, alive, resolve, request, new, url, subdomain, port, level,'
|
||||
f'cname, content, public, cdn, status, reason, title, banner, header,'
|
||||
f'history, response, times, ttl, cidr, asn, org, ip2region,'
|
||||
f'ip2location, resolver, module, source, elapse, find) '
|
||||
f'values (:id, :alive, :resolve, :request, :new, :url, '
|
||||
f'history, response, times, ttl, cidr, asn, org, addr, isp, resolver,'
|
||||
f'module, source, elapse, find) '
|
||||
f'values (:id, :alive, :resolve, :request, :new, :url,'
|
||||
f':subdomain, :port, :level, :cname, :content, :public, :cdn,'
|
||||
f':status, :reason, :title, :banner, :header, :history, :response,'
|
||||
f':times, :ttl, :cidr, :asn, :org, :ip2region, :ip2location,'
|
||||
f':resolver, :module, :source, :elapse, :find)', results)
|
||||
f':times, :ttl, :cidr, :asn, :org, :addr, :isp, :resolver, :module,'
|
||||
f':source, :elapse, :find)', results)
|
||||
except Exception as e:
|
||||
logger.log('ERROR', e)
|
||||
|
||||
@@ -231,7 +231,7 @@ class Database(object):
|
||||
table_name = table_name.replace('.', '_')
|
||||
query = f'select id, new, alive, request, resolve, url, subdomain, level,' \
|
||||
f'cname, content, public, cdn, port, status, reason, title, banner,' \
|
||||
f'cidr, asn, org, ip2region, ip2location, source from "{table_name}"'
|
||||
f'cidr, asn, org, addr, isp, source from "{table_name}"'
|
||||
if alive and limit:
|
||||
if limit in ['resolve', 'request']:
|
||||
where = f' where {limit} = 1'
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import zipfile
|
||||
from IP2Location import IP2Location
|
||||
from config.setting import data_storage_dir
|
||||
|
||||
|
||||
class IpGeoInfo(IP2Location):
|
||||
def __init__(self):
|
||||
zip_path = data_storage_dir.joinpath("IP2LOCATION-LITE-DB3.BIN.ZIP")
|
||||
bin_path = data_storage_dir.joinpath("IP2LOCATION-LITE-DB3.BIN")
|
||||
if not bin_path.exists():
|
||||
zf = zipfile.ZipFile(zip_path)
|
||||
zf.extract('IP2LOCATION-LITE-DB3.BIN', data_storage_dir)
|
||||
IP2Location.__init__(self, bin_path)
|
||||
+4
-4
@@ -284,8 +284,8 @@ class Module(object):
|
||||
'cidr': None,
|
||||
'asn': None,
|
||||
'org': None,
|
||||
'ip2region': None,
|
||||
'ip2location': None,
|
||||
'addr': None,
|
||||
'isp': None,
|
||||
'resolver': None,
|
||||
'module': self.module,
|
||||
'source': self.source,
|
||||
@@ -335,8 +335,8 @@ class Module(object):
|
||||
'cidr': info.get('cidr'),
|
||||
'asn': info.get('asn'),
|
||||
'org': info.get('org'),
|
||||
'ip2region': info.get('ip2region'),
|
||||
'ip2location': info.get('ip2location'),
|
||||
'addr': info.get('addr'),
|
||||
'isp': info.get('isp'),
|
||||
'resolver': info.get('resolver'),
|
||||
'module': self.module,
|
||||
'source': self.source,
|
||||
|
||||
+8
-12
@@ -5,12 +5,10 @@ from config.log import logger
|
||||
from config import settings
|
||||
from common import utils
|
||||
from common.ipasn import IPAsnInfo
|
||||
from common.ipgeo import IpGeoInfo
|
||||
from common.ipreg import IpRegData
|
||||
|
||||
|
||||
ip_asn = IPAsnInfo()
|
||||
ip_geo = IpGeoInfo()
|
||||
ip_reg = IpRegData()
|
||||
|
||||
|
||||
@@ -85,8 +83,8 @@ def gen_infos(data, qname, info, infos):
|
||||
cidrs = list()
|
||||
asns = list()
|
||||
orgs = list()
|
||||
locs = list()
|
||||
regs = list()
|
||||
addrs = list()
|
||||
isps = list()
|
||||
answers = data.get('answers')
|
||||
for answer in answers:
|
||||
if answer.get('type') == 'A':
|
||||
@@ -102,12 +100,10 @@ def gen_infos(data, qname, info, infos):
|
||||
cidrs.append(asn_info.get('cidr'))
|
||||
asns.append(asn_info.get('asn'))
|
||||
orgs.append(asn_info.get('org'))
|
||||
loc = f'{ip_geo.get_country_long(ip)} ' \
|
||||
f'{ip_geo.get_region(ip)} ' \
|
||||
f'{ip_geo.get_city(ip)}'
|
||||
locs.append(loc)
|
||||
reg = ip_reg.query(ip).get('addr')
|
||||
regs.append(reg)
|
||||
addr = ip_reg.query(ip).get('addr')
|
||||
addrs.append(addr)
|
||||
isp = ip_reg.query(ip).get('isp')
|
||||
isps.append(isp)
|
||||
info['resolve'] = 1
|
||||
info['reason'] = 'OK'
|
||||
info['cname'] = ','.join(cname)
|
||||
@@ -117,8 +113,8 @@ def gen_infos(data, qname, info, infos):
|
||||
info['cidr'] = ','.join(cidrs)
|
||||
info['asn'] = ','.join(asns)
|
||||
info['org'] = ','.join(orgs)
|
||||
info['ip2location'] = ','.join(locs)
|
||||
info['ip2region'] = ','.join(regs)
|
||||
info['addr'] = ','.join(addrs)
|
||||
info['isp'] = ','.join(isps)
|
||||
infos[qname] = info
|
||||
if not flag:
|
||||
info['alive'] = 0
|
||||
|
||||
Reference in New Issue
Block a user