コード例 #1
0
ファイル: ip_handler.py プロジェクト: EdwinYang2000/week6
    def handle(self, message):
        if not self.check_match(message):
            return


        parts = message.content.strip().split()

        if len(parts) == 1 or len(parts) > 2:
            return create_reply('command wrong, correct format ip 123.123.123.123', message)

        ip = parts[1]
        print (ip)

        patterns = r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'

        if not re.match(patterns, ip):
            return create_reply('wrong ip addresss',message)

        file = '/Users/yangedwin/workspace/week6/rmon/qqwry.dat'
        q = QQwry()
        q.load_file(file)
        result = q.lookup(ip)
        print (result)

        if result is None:
            return create_reply('could not find this address',message)
        else:
            return create_reply(result[0],message)
コード例 #2
0
ファイル: handlers.py プロジェクト: Manchangdx/redis-board
class IPLocationHandler(BaseHandler):
    """处理 IP 消息,返回 IP 地理位置
    """

    command = 'ip'

    def __init__(self, wx_client=None):
        """获取 IP 地址数据
        """
        super().__init__()
        file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            '../static/qqwry.dat')
        self.q = QQwry()
        self.q.load_file(file)

    def handle(self, message):
        # 判断消息开头是否匹配
        if not self.check_match(message):
            return
        parts = message.content.strip().split()
        if len(parts) == 1 or len(parts) > 2:
            return create_reply('IP 地址无效', message)
        ip = parts[1]
        pattern = r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'
        if not re.match(pattern, ip):
            return create_reply('IP 地址无效', message)
        result = self.q.lookup(ip)
        if result:
            return create_reply(result[0], message)
        return create_reply('未找到 IP 对应的地址', message)
コード例 #3
0
class IP2Region():
    '''
    解析ip地址:lookup(ip)方法将ip转化成("省份","地区")
    '''

    def __init__(self):
        self.filename = 'qqwry.dat'
        self.dat_path = os.path.join(base_config.BASE_PATH, 'utils', self.filename)
        self.q = QQwry()
        if os.path.exists(self.dat_path):
            self.q.load_file(self.dat_path)
            print(self.q)
        else:

            print('初始化更新ip库')
            self.update_dat()
            self.reload_dat()
            return

    def get_lastone(self):
        '''
        返回最后一条数据,最后一条通常为数据的版本号
        没有数据则返回一个None
        :return:
        '''
        version = self.q.get_lastone()
        return version

    def update_dat(self):
        '''
        异步更新,使用线程或者celery更新IP数据库源
        :return:(bool) 成功后返回一个正整数,是文件的字节数;失败则返回一个负整数。
        '''
        result = updateQQwry(self.dat_path)
        if result > 0:
            print('ip库更新成功')
            return True
        print('ip库更新失败,网络出现故障')
        return False

    def lookup(self, ip):
        '''
        解析ip地址
        :param ip(str): 要解析的ip地址
        :return: 找到则返回一个含有两个字符串的元组,如:('国家', '省份')没有找到结果,则返回一个None
        '''
        return self.q.lookup(ip)

    def reload_dat(self):
        '''
        重载IP数据源,当IPdat数据更新的时候,使用此方法更新数据
        :return: (bool) 重载成功返回True,重载失败返回Flase
        '''
        self.q.clear()
        if not self.q.is_loaded():
            self.q.load_file(self.dat_path)
            return True
        return False
コード例 #4
0
class Fetcher(object):
    name = "fetcher"

    def __init__(self):
        self.log = LogHandler(self.name)
        self.conf = ConfigHandler()
        self.proxy_handler = ProxyHandler()
        self.loadIp()

    def loadIp(self):
        if False != os.path.isfile("qqwry.dat"):
            self.ip = QQwry()
            self.ip.load_file('qqwry.dat')
        else:
            self.ip = False

    def fetch(self):
        """
        fetch proxy into db with proxyFetcher
        :return:
        """
        proxy_set = set()
        self.log.info("ProxyFetch : start")
        for fetch_name in self.conf.fetchers:
            self.log.info("ProxyFetch - {func}: start".format(func=fetch_name))
            fetcher = getattr(ProxyFetcher, fetch_name, None)
            if not fetcher:
                self.log.error("ProxyFetch - {func}: class method not exists!")
                continue
            if not callable(fetcher):
                self.log.error("ProxyFetch - {func}: must be class method")
                continue

            try:
                for proxy in fetcher():
                    if proxy in proxy_set:
                        self.log.info('ProxyFetch - %s: %s exist' %
                                      (fetch_name, proxy.ljust(23)))
                        continue
                    else:
                        self.log.info('ProxyFetch - %s: %s success' %
                                      (fetch_name, proxy.ljust(23)))

                    if proxy.strip():
                        if self.ip:
                            area = " ".join(self.ip.lookup(
                                proxy.split(':')[0]))
                        else:
                            self.loadIp()
                            area = ''
                        proxy_set.add((proxy, fetch_name, area))

            except Exception as e:
                self.log.error(
                    "ProxyFetch - {func}: error".format(func=fetch_name))
                self.log.error(str(e))
        self.log.info("ProxyFetch - all complete!")
        return proxy_set
コード例 #5
0
def get_country(proxy):
    q = QQwry()
    q.load_file('../qqwry.dat')
    list = proxy.split(':')
    ip = list[1].strip('/')
    country = q.lookup(ip)
    if (country):
        return country[0]
    return None
コード例 #6
0
def getip_info_local(ip):
    try:
        q = QQwry()
        q.load_file('./qqwry.dat')
        result = q.lookup(ip)
        area = result[0]
        isp = result[1]
        return area, isp, True
    except Exception:
        return '', '', False
コード例 #7
0
def handle_ip(ip):
    q = QQwry()
    q.load_file(QQwrydat.path)
    _ = q.lookup(ip)
    with PeiZhi() as db:
        data = db.get_peizhi()
    if data['need_switch'] == 1:
        now = time.strftime("%H:%M", time.localtime())
        if now >= data['switch_time_start'] and now <= data['switch_time_end']:
            with Sheng() as db:
                for i in db.get_need_switch():
                    if i in _[0]:
                        return True
    return False
コード例 #8
0
ファイル: czip.py プロジェクト: sempr/ipservice
def load_qqwry():
    ipq = QQwry()
    res = ipq.load_file(IP_DATA_FILE, loadindex=True)
    if not res:
        print("qqwry load failed", IP_DATA_FILE)
        sys.exit(-1)
    return ipq
コード例 #9
0
ファイル: ip_handler.py プロジェクト: MingjunWu/louPlus
 def handle(self, message):
     if not self.check_match(message):
         return 
     lookup_data = message.content.strip().split()
     if len(lookup_data) == 1 or len(lookup_data) > 2:
         return create_reply("invalid IP", message)
     ip = lookup_data[1]
     if not re.match(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$',ip):
         return create_reply("IP invalid", message)
     q = QQwry()
     q.load_file('qqwry.dat')
     
     reply = q.lookup(ip)
     if reply is None:
         return None
     return create_reply(reply[0], message)
     
コード例 #10
0
def get_city_of_ip(ip):
    """根据IP地址获取城市名称"""
    q = QQwry()
    res = q.load_file(config.IP_DATABASE_FILENAME, loadindex=False)
    if res:
        result = q.lookup(ip)
        q.clear()
        return result[0]
コード例 #11
0
ファイル: util.py プロジェクト: vsyour/pyShell
class qqwry_search(object):
    """docstring for qqwry_search"""
    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, "instance"):
            cls.instance = super(qqwry_search, cls).__new__(cls)
        return cls.instance

    def __init__(self):
        from qqwry import QQwry
        self.q = QQwry()
        self.q.load_file('qqwry.dat')

    def __call__(self, ip: str):
        return ' '.join(self.q.lookup(ip))

    def __del__(self):
        self.q.clear()
コード例 #12
0
ファイル: views.py プロジェクト: sloww/checklist
def add_scan_record(qr_label, ip):
    q = QQwry()
    sr = ScanRecord()
    sr.ip = ip
    sr.qr_label = qr_label
    if q.load_file(settings.QQPATH):
        sr.json = q.lookup(str(ip))
        sr.city = sr.json[0]
    sr.save()
コード例 #13
0
def listSql():

    page = request.args.get('page', 1, type=int)
    listt = Role.query.all()
    pagination = IpList.query.order_by(IpList.time.desc()).paginate(
        page, per_page=15, error_out=False)
    ip = pagination.items
    for i in ip:
        ip_data = i.ip
        q = QQwry()
        filename = os.path.join(STATIC_DIR, 'qqwry.dat')
        q.load_file(filename, loadindex=False)
        adders = q.lookup(ip_data)
        query_ip = IpList.query.order_by(
            IpList.time.desc()).filter_by(ip=ip_data).first()
        query_ip.adders = str(adders)
        db.session.commit()

    return render_template('list.html',
                           ip=ip,
                           pagination=pagination,
                           listt=listt)
コード例 #14
0
class IPLocationHandler(CommandHandler):
    command = 'ip'

    def __init__(self):
        file = os.environ.get('QQWRY_DAT', 'qqwry.dat')
        self.q = QQwry()
        self.q.load_file(file)

    def handle(self, message):
        if not self.check_match(message):
            return
        parts = message.content.strip().split()
        if len(parts) == 1 or len(parts) > 2:
            return create_reply('IP地址无效', message)
        ip = parts[1]
        pattern = r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'
        if not re.match(pattern, ip):
            return create_reply('IP地址无效', message)
        result = self.q.lookup(ip)
        if result is None:
            return create_reply('未找到', message)
        else:
            return create_reply(result[0], message)
コード例 #15
0
class IPLocationHandler(CommandHandler):
    command = 'ip'

    def __init__(self):
        file = os.environ.get('QQWRY_DAT', 'qqwry.dat')
        self.q = QQwry()
        self.q.load_file(file)

    def handle(self, message):
        if not self.check_match(message):
            return
        parts = message.content.strip().split()
        if len(parts) == 1 or len(parts) > 2:
            return create_reply('IP地址无效', message)
        ip = parts[1]
        pattern = r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'
        if not re.match(pattern, ip):
            return create_reply('IP地址无效', message)
        result = self.q.lookup(ip)
        if result is None:
            return create_reply('未找到', message)
        else:
            return create_reply(result[0], message)
コード例 #16
0
def get_raw_data():
    """
    得到raw_data
    :return:返回预处理后的数据
    """
    filename = LOG_PATH
    qqwry_path = QQWRY_PATH

    ip_dict = {}  # 存不重复的ip及其city
    log_text = get_log_text(filename)  # 获取日志原始文件
    parsed_log_list = parse(log_text)  # 获取解析完的日志

    # 加载纯真ip数据库
    flag = 0
    q = QQwry()
    while not q.is_loaded():
        # 加载3次失败后改用其他方案
        if flag == 3:
            break
        q.load_file(qqwry_path)
        flag += 1

    raw_data = []
    Ip_raw_data = namedtuple(
        'ip_data',
        ['log_time', 'ip', 'referrer', 'client', 'method', 'status', 'city'])
    for line in parsed_log_list:
        log_time = parse_nginx_date(line['date'] + ':' + line['time'],
                                    line['tz'])
        log_ip = line['origin']
        if log_ip not in ip_dict:
            ip_dict[log_ip] = get_address_by_ip(line, q, flag)
        log_city = ip_dict[log_ip]
        raw_data.append(
            Ip_raw_data(log_time, log_ip, line['referrer'], line['client'],
                        line['method'], line['status'], log_city))
    return raw_data
コード例 #17
0
def batch_query_and_print():
    county = set()
    vps = set()
    ip = set()
    q = QQwry()
    q.load_file('qqwry.dat')
    with open('ip1.txt') as f:
        ip_list = f.read().splitlines()
        for read_content in ip_list:
            try:
                IP(read_content)
            except:
                print("有不符合规范的IP地址,请检查后重新运行")
                exit(0)
    address_list = [q.lookup(ip) for ip in ip_list]
    for i, j in zip(ip_list, address_list):
        query_results = i + " " + j[0] + " " + j[1]
        county.add(j[0])
        vps.add(j[1])
        ip.add(i)
        print(len(ip), len(county), len(vps))
        with open("query_results.txt", 'a', encoding='utf-8') as f:
            f.writelines(query_results + "\n")
        print(query_results)
コード例 #18
0
ファイル: ip.py プロジェクト: hu0514/script
from qqwry import QQwry
q = QQwry()

#filename可以是qqwry.dat的文件名也可以是bytes类型的文件内容
#当参数loadindex=False时 加载速度快进程内存少查询速度慢
#当参数loadindex=True时 加载速度慢进程内存多查询速度快
q.load_file('qqwry.dat', loadindex=False)
result = q.lookup('8.8.8.8')
print(result)
コード例 #19
0
#!/usr/bin/python
import base64
import time
import sys, os
import socket
from qqwry import QQwry
q = QQwry()
q.load_file('qqwry/qqwry.dat')

configfilepath = 'configfile/'


def ToBase64(file, txt):
    with open(file, 'rb') as fileObj:
        image_data = fileObj.read()
        base64_data = base64.b64encode(image_data)
        fout = open(txt, 'w')
        fout.write(base64_data.decode())
        fout.close()


def ToFile(txt, file):
    with open(txt, 'r') as fileObj:
        base64_data = fileObj.read()
        ori_image_data = base64.b64decode(base64_data)
        fout = open(file, 'wb')
        fout.write(ori_image_data)
        fout.close()


#ToBase64("./desk.jpg",'desk_base64.txt')  # 文件转换为base64
コード例 #20
0
ファイル: method_localdb.py プロジェクト: 0xr0ot/PY_self
###########################################  纯真ip  ######################################

#https://github.com/animalize/qqwry-python3
#https://github.com/gwind/ylinux/tree/master/tools/IP/QQWry
#https://segmentfault.com/a/1190000000352578

##更新本地dat文件
#from qqwry import updateQQwry
#result = updateQQwry('qqwry.dat')

##use
from qqwry import QQwry

q = QQwry()
q.load_file('qqwry.dat')#工作路径
result = q.lookup('xxx.xxx.xx.xx')
print(result)

######################################  ipip.net  #########################################

#https://github.com/17mon/python

import os
from ipip import IP#目前无法pip(python3.5.1)
from ipip import IPX

IP.load(os.path.abspath("mydata4vipday2.dat"))#工作路径
print IP.find("118.28.8.8")

IPX.load(os.path.abspath("mydata4vipday2.datx"))#工作路径
print IPX.find("118.28.8.8")
コード例 #21
0
import xlrd
from qqwry import QQwry

q = QQwry()
# 加载纯真镜像 dat 文件
# https://github.com/WisdomFusion/qqwry.dat
q.load_file('F:\qqwry.dat')

# 打开存储 IP 的 excel 表格
wb = xlrd.open_workbook(filename="IP.xlsx")
# 对应到目标表
ip = wb.sheet_by_index(0)
# 从上到下,按列
rows = ip.nrows
# 将结果保存在 result.txt 中
ipResult = open("result.txt", 'w')
for i in range(rows):
    # 得到每一个 IP
    ip_value = ip.cell(i, 0).value
    # 查询
    result = q.lookup(ip_value)
    print(result)
    city = result[0]
    isp = result[1]
    ipResult.write(ip_value + '\t' + city + '\t' + isp + '\r\n')
ipResult.close()
コード例 #22
0
ファイル: ip.py プロジェクト: liangjiawen1998/shu-s-project
'''
Author: Dong Xing
Date: 2021-01-15 20:05:06
LastEditors: Dong Xing
LastEditTime: 2021-01-17 02:58:51
Description: file content
'''
from fastapi import Query, APIRouter, Request
from qqwry import QQwry

q = QQwry()
q.load_file('./data/qqwry.dat')

router = APIRouter()


@router.get("/ipcity/")
async def get_ipcity(ip: str):
    # 数据来源:https://github.com/ipipdotnet/ipdb-php
    result = q.lookup(ip)
    if result:
        return {'code': 200, 'city': result[0], 'operator': result[1]}
    else:
        return {'code': 404, 'city': None, 'operator': None}


@router.get("/ip/")
async def read_root(request: Request):
    client_host = request.client.host
    return {"client_host": client_host}
コード例 #23
0
  if not os.path.exists('QQway.dat'):
      print("%sDownload QQwry.dat" % ret_time())
      download_ret = updateQQwry('QQway.dat')
      if int(download_ret) < 0:
          print("%sDownload QQwry.dat Error:" % ret_time(), int(download_ret))
          print("-1:下载copywrite.rar时出错\n"
                "-2:解析copywrite.rar时出错\n"
                "-3:下载qqwry.rar时出错\n"
                "-4:qqwry.rar文件大小不符合copywrite.rar的数据\n"
                "-5:解压缩qqwry.rar时出错\n"
                "-6:保存到最终文件时出错")
          sys.exit()
      else:
          print("%sDownload QQwry.dat Success~ Status:%s" % (ret_time(), int(download_ret)))
  qq_wry = QQwry()
  qq_wry.load_file('QQway.dat')
  # Run
  print(
      'Init->IP Data: Load:%s Version:%s-%s' % (qq_wry.is_loaded(), qq_wry.get_lastone()[0], qq_wry.get_lastone()[1]))
  print('Init->Start Time: %s' % ret_time())
  print('################################################\n')
 	#sys.argv.append('*')
  #sys.argv.append('200')
  global SETTHREAD
  global ip_file
  global ip_info_file
 
  try:
      SETTHREAD = sys.argv[2]
      ip_file = open("./results/IP-%s段.txt" % sys.argv[1].split('-')[0], "w")
      ip_info_file = open("./results/IP归属地-%s段.txt" % sys.argv[1].split('-')[0], "w")
コード例 #24
0
ファイル: utils.py プロジェクト: wangjun/qrcode_track
# coding=utf8
from qqwry import QQwry
from datetime import datetime
from ua_parser import user_agent_parser
from settings import HOST
from urllib.parse import quote
from settings import MONGODB_HOST, MONGODB_PORT, DATABASE, COLLECTION
from pymongo import MongoClient


q = QQwry()
q.load_file('qqwry.dat', loadindex=False)

client = MongoClient(MONGODB_HOST, MONGODB_PORT)
db = client[DATABASE]
collection = db[COLLECTION]


def analyse_client(ip, ua):
    data = {}
    data['time'] = datetime.now()
    data['location'] = get_loc_from_ip(ip)
    data['client'] = user_agent_parser.Parse(ua)
    collection.insert(data)


def get_loc_from_ip(ip):
    loc, supplier = q.lookup(ip)
    return {
        'ip': ip,
        'loc': loc,
コード例 #25
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'caijinxu'

from qqwry import QQwry
q = QQwry()
q.load_file('app/libs/qqwry.dat')
# q.load_file('qqwry.dat')

lang_cou = """af	南非语
af-ZA	南非语
ar	阿拉伯语
ar-AE	阿拉伯语(阿联酋)
ar-BH	阿拉伯语(巴林)
ar-DZ	阿拉伯语(阿尔及利亚)
ar-EG	阿拉伯语(埃及)
ar-IQ	阿拉伯语(伊拉克)
ar-JO	阿拉伯语(约旦)
ar-KW	阿拉伯语(科威特)
ar-LB	阿拉伯语(黎巴嫩)
ar-LY	阿拉伯语(利比亚)
ar-MA	阿拉伯语(摩洛哥)
ar-OM	阿拉伯语(阿曼)
ar-QA	阿拉伯语(卡塔尔)
ar-SA	阿拉伯语(沙特阿拉伯)
ar-SY	阿拉伯语(叙利亚)
ar-TN	阿拉伯语(突尼斯)
ar-YE	阿拉伯语(也门)
az	阿塞拜疆语
az-AZ	阿塞拜疆语(拉丁文)
az-AZ	阿塞拜疆语(西里尔文)
コード例 #26
0
class SQLite3Client:
    """
    代理池依赖了 Redis 数据库,使用了其`有序集合`的数据结构
    (可按分数排序,key 值不能重复)
    """

    def __init__(self, FILENAME=SQLITE3_FILENAME):
        self.conn = g_conn #sqlite3.connect(FILENAME)
        self.cursor = self.conn.cursor()
        self.wry = QQwry()
        self.wry.load_file(QQWRY_FILENAME)

    def add_proxy(self, proxy, score=INIT_SCORE):
        """
        新增一个代理,初始化分数 INIT_SCORE < MAX_SCORE,确保在
        运行完收集器后还没运行校验器就获取代理,导致获取到分数虽为 MAX_SCORE,
        但实际上确是未经验证,不可用的代理

        :param proxy: 新增代理
        :param score: 初始化分数
        """
        country = self.get_country(proxy)
        type = self.get_proxy_type(proxy)
        sql = "INSERT INTO Proxy (PROXY, TYPE, COUNTRY, SPEED, SCORE) VALUES('%s', '%s', '%s', %f, %d)"\
            % (proxy, type, country, 100.0, score)
        try:
            self.cursor.execute(sql)
            self.conn.commit()
        except Exception:
            pass

    def reduce_proxy_score(self, proxy):
        """
        验证未通过,分数减一

        :param proxy: 验证代理
        """
        sql = "select SCORE from Proxy where PROXY=='%s'" % proxy
        cur = self.cursor.execute(sql)
        value = cur.fetchone()
        score = int(value[0])
        if score and score > MIN_SCORE:
            score -= 1
            sql = "UPDATE Proxy set SCORE=%d where PROXY=='%s'" %(score, proxy)
        else:
            sql = "DELETE from Proxy where PROXY=='%s'" % proxy
        self.cursor.execute(sql)
        self.conn.commit()

    def increase_proxy_score(self, proxy):
        """
        验证通过,分数加一

        :param proxy: 验证代理
        """
        sql = "select SCORE from Proxy where PROXY=='%s'" % proxy
        cur = self.cursor.execute(sql)
        value = cur.fetchone()
        score = int(value[0])
        if score and score < MAX_SCORE:
            score += 1
            sql = "UPDATE Proxy set SCORE=%d where PROXY=='%s'" % (score, proxy)
        self.cursor.execute(sql)
        self.conn.commit()
    def update_proxy_speed(self, proxy, speed):
        try:
            sql = "UPDATE Proxy set SPEED=%f, TIME = datetime('now','localtime') where PROXY=='%s'" % (speed, proxy)
            self.cursor.execute(sql)
            self.conn.commit()
            return True
        except Exception:
            return False
    def pop_proxy(self):
        """
        返回一个代理
        """
        # 第一次尝试取分数最高,也就是最新可用的代理
        sql = "SELECT PROXY FROM Proxy ORDER BY SCORE DESC LIMIT 1"
        cur = self.cursor.execute(sql)
        value = cur.fetchone()
        if value:
            return value[0]
        return 0


    def get_proxies(self, count=1):
        """
        返回指定数量代理,分数由高到低排序

        :param count: 代理数量
        """
        #print("count:%d" %count)
        sql = "SELECT PROXY FROM Proxy ORDER BY SCORE DESC LIMIT %d" % count
        cur = self.cursor.execute(sql)
        #print(cur.fetchall())
        for row in cur.fetchall():
            yield row[0]

    def count_all_proxies(self):
        """
        返回所有代理总数
        """
        sql = "SELECT COUNT(*) FROM Proxy"
        cur = self.cursor.execute(sql)
        value = cur.fetchone()
        if value:
            return value[0]
        return 0

    def count_score_proxies(self, score):
        """
        返回指定分数代理总数

        :param score: 代理分数
        """
        if 0 <= score <= 10:
            sql = "SELECT COUNT(*) FROM Proxy WHERE SCORE==%d" % score
            cur = self.cursor.execute(sql)
            value = cur.fetchone()
            if value:
                return value[0]
        return -1
    def get_score_proxies(self, score):
        """
        返回数据库的中制定的score的所有数据

        :param score: 代理分数
        """
        list = []
        sql = "SELECT PROXY FROM Proxy WHERE SCORE== %d" % score
        values = self.cursor.execute(sql)
        for row in values:
            list.append(row[0])
        return list

    def clear_proxies(self, score):
        """
        删除分数小于等于 score 的代理
        """
        if 0 <= score <= 10:
            sql = "DELETE from Proxy WHERE SCORE <= %d" % score
            self.cursor.execute(sql)
            self.conn.commit()
            return True
        return False

    def get_country(self, proxy):
        pro_split_list = proxy.split(':')
        ip = pro_split_list[1].strip('/')
        ipcountry = self.wry.lookup(ip)
        if ipcountry:
            return ipcountry[0]
        return None
    def get_proxy_type(self, proxy):
        pro_split_list = proxy.split(':')
        if pro_split_list[0].find('http') >=0:
            return pro_split_list[0]
        return None
    def all_proxies(self):
        """
        返回全部代理
        """
        list=[]
        sql = "SELECT PROXY FROM Proxy"
        values = self.cursor.execute(sql)
        for row in values:
            list.append(row[0])
        return list
    def __del__(self):
        self.conn.close()
# if __name__=='__main__':
#     #test_main(proxyAddressArray)
#     gou = SQLite3Client()
#     proxy_all_list = gou.get_proxies(1)
#     for proxy in proxy_all_list:
#         print(proxy)
#     print("pop: %s" % gou.pop_proxy())
#     #gou.clear_proxies(9)
#     print("count_score_proxies:%d" %gou.count_score_proxies(9))
#     print("count_all_proxies:%d" % gou.count_all_proxies())
#     proxy_val = 'http://103.199.159.177:40049'
#     #gou.increase_proxy_score(proxy_val)
#     gou.reduce_proxy_score(proxy_val)
#     #gou.add_proxy()
コード例 #27
0
    def dealEmitSlot(self, data):
        url = data[0]
        password = data[1]
        memo = data[2]
        UseRSA = data[3]
        script = data[4]
        if self.row_num == -1:
            self.index = self.shellTableWidget.rowCount()
            self.shellTableWidget.setRowCount(self.index + 1)
        else:
            self.index = self.row_num

        # 添加URL
        newItem = QtWidgets.QTableWidgetItem(url)
        newItem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
        self.shellTableWidget.setItem(self.index, 0, newItem)

        # 添加IP
        ip = dns_resolver(url)
        newItem = QtWidgets.QTableWidgetItem(ip)
        newItem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
        self.shellTableWidget.setItem(self.index, 1, newItem)

        # 添加密码
        newItem = QtWidgets.QTableWidgetItem(password)
        newItem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
        self.shellTableWidget.setItem(self.index, 2, newItem)

        # 添加物理地址
        q = QQwry()
        q.load_file(os.path.dirname(__file__) + '/qqwry.dat')
        try:
            res = q.lookup(ip)
            addr = res[0] + ' ' + res[1]
        except:
            addr = ''
        newItem = QtWidgets.QTableWidgetItem(addr)
        newItem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
        self.shellTableWidget.setItem(self.index, 3, newItem)

        # 添加备注
        newItem = QtWidgets.QTableWidgetItem(memo)
        newItem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
        self.shellTableWidget.setItem(self.index, 4, newItem)

        # 添加时间
        newItem = QtWidgets.QTableWidgetItem(
            time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
        newItem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
        self.shellTableWidget.setItem(self.index, 5, newItem)

        # 是否进行流量加密
        if UseRSA:
            newItem = QtWidgets.QTableWidgetItem('是')
        else:
            newItem = QtWidgets.QTableWidgetItem('否')
        newItem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
        self.shellTableWidget.setItem(self.index, 6, newItem)

        # 添加脚本类型
        newItem = QtWidgets.QTableWidgetItem(script)
        newItem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
        self.shellTableWidget.setItem(self.index, 7, newItem)
コード例 #28
0
ファイル: Host_Info.py プロジェクト: do0dl3/LangSrcCurise
@file: 获取IP信息.py
"""
import IPy
import nmap
import socket
socket.setdefaulttimeout(25)
from urllib.parse import urlparse
import requests
requests.packages.urllib3.disable_warnings()
import time
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from qqwry import QQwry
from scapy.all import *
q = QQwry()
import os
q.load_file(os.path.join('Auxiliary', 'IP_ADDRESS.dat'))

import django
import os
import sys
pathname = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, pathname)
sys.path.insert(0, os.path.abspath(os.path.join(pathname, '..')))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "LangSrcCurise.settings")
django.setup()
from app.models import Setting, Error_Log

Set = Setting.objects.all()[0]
pool_count = int(Set.Pool)
Alive_Status = eval(Set.Alive_Code)
コード例 #29
0
"""
import IPy
import nmap
import socket
import re
import time
socket.setdefaulttimeout(25)
from urllib.parse import urlparse
import requests
requests.packages.urllib3.disable_warnings()
from concurrent.futures import ProcessPoolExecutor,ThreadPoolExecutor
from qqwry import QQwry
from scapy.all import *

q = QQwry()
q.load_file('IP_ADDRESS.dat')


Alive_Status = [200,301,302,404]
# 判断存活验证码·机制,实际清空会写在配置文件中

Banner = {b'http': [b'^HTTP/.*\nServer: Apache/2'], b'ssh': [b'^SSH-.*openssh'], b'netbios': [b'\xc2\x83\x00\x00\x01\xc2\x8f'], b'backdoor-fxsvc': [b'^500 Not Loged in'], b'backdoor-shell': [b'^sh[$#]'], b'bachdoor-shell': [b'[a-z]*sh: .* command not found'], b'backdoor-cmdshell': [b'^Microsoft Windows .* Copyright .*>'], b'db2': [b'.*SQLDB2RA'], b'db2jds': [b'^N\x00'], b'dell-openmanage': [b'^N\x00\r'], b'finger': [b'finger: GET: '], b'ftp': [b'^220 .* UserGate'], b'http-iis': [b'^<h1>Bad Request .Invalid URL.</h1>'], b'http-jserv': [b'^HTTP/.*Cookie.*JServSessionId'], b'http-tomcat': [b'.*Servlet-Engine'], b'http-weblogic': [b'^HTTP/.*Cookie.*WebLogicSession'], b'http-vnc': [b'^HTTP/.*RealVNC/'], b'ldap': [b'^0E'], b'smb': [b'^\x00\x00\x00.\xc3\xbfSMBr\x00\x00\x00\x00.*'], b'msrdp': [b'^\x03\x00\x00\x0b\x06\xc3\x90\x00\x004\x12\x00'], b'msrdp-proxy': [b'^nmproxy: Procotol byte is not 8\n$'], b'msrpc': [b'\x05\x00\r\x03\x10\x00\x00\x00\x18\x00\x00\x00....\x04\x00\x01\x05\x00\x00\x00\x00$'], b'mssql': [b';MSSQLSERVER;'], b'telnet': [b'^\xc3\xbf\xc3\xbe'], b'mysql': [b"whost '"], b'mysql-blocked': [b'^\\(\x00\x00'], b'mysql-secured': [b'this MySQL'], b'mongodb': [b'^.*version.....([\\.\\d]+)'], b'nagiosd': [b'Sorry, you \\(.*are not among the allowed hosts...'], b'nessus': [b'< NTP 1.2 >\nUser:'******'oracle-tns-listener': [b'\\(ADDRESS=\\(PROTOCOL='], b'oracle-dbsnmp': [b'^\x00\x0c\x00\x00\x04\x00\x00\x00\x00'], b'oracle-https': [b'^220- ora'], b'oracle-rmi': [b'^N\x00\t'], b'postgres': [b'^EFATAL'], b'rlogin': [b'^\x01Permission denied.\n'], b'rpc-nfs': [b'^\x02\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00'], b'rpc': [b'^\xc2\x80\x00\x00'], b'rsync': [b'^@RSYNCD:.*'], b'smux': [b'^A\x01\x02\x00'], b'snmp-public': [b'public\xc2\xa2'], b'snmp': [b'A\x01\x02'], b'socks': [b'^\x05[\x00-\x08]\x00'], b'ssl': [b'^\x16\x03\x00..\x02...\x03\x00'], b'sybase': [b'^\x04\x01\x00'], b'tftp': [b'^\x00[\x03\x05]\x00'], b'uucp': [b'^login: password: '******'vnc': [b'^RFB.*'], b'webmin': [b'^0\\.0\\.0\\.0:.*:[0-9]'], b'websphere-javaw': [b'^\x15\x00\x00\x00\x02\x02\n']}


def get_title(r):
    title = '获取失败'
    try:
        encoding = requests.utils.get_encodings_from_content(r.text)[0]
        content = r.content.decode(encoding,'replace')
        title_pattern = '<title>(.*?)</title>'
        title = re.search(title_pattern, content, re.S | re.I).group(1)
コード例 #30
0
ファイル: pilllll.py プロジェクト: lichongbing/all-in
def query(ip):
    q = QQwry()
    q.load_file('D://flask1/apps/static/qqwry.dat',loadindex=False)
    result = q.lookup(ip)
    print(result)