コード例 #1
0
def Add_Data_To_Url(urls):
    for url in urls:
        try:
            res = Get_Url_Info(url).get_info()
            res_url = res.get('url')
            res_title = res.get('title')
            res_power = res.get('power')
            res_server = res.get('server')
            Other_Url.objects.create(url=res_url,
                                     title=res_title,
                                     power=res_power,
                                     server=res_server)
        except Exception as e:
            print('错误代码 [29] {}'.format(str(e)))
            Error_Log.objects.create(url=url,
                                     error='错误代码 [29] {}'.format(str(e)))
        try:
            ip = get_host(url)
            if ip == '获取失败':
                return
            print('URL --> {}  IP --> {}'.format(url, ip))
            URL.objects.create(url=url, ip=ip)

            test_ip = list(IP.objects.filter(ip=ip))
            if test_ip != []:
                return
            IP_Res = Get_Ip_Info(ip)
            servers = IP_Res.get_server_from_nmap(ip)
            # 服务与端口  字典类型
            open_port = servers.keys()
            check_alive_url = []
            for port in open_port:
                check_alive_url.append('http://{}:{}'.format(ip, port))
                check_alive_url.append('https://{}:{}'.format(ip, port))
            alive_url = Get_Alive_Url(check_alive_url)
            # 该IP上存活WEB,类型为列表,内容为多个字典
            host_type = IP_Res.get_host_type(ip)
            # windows/linux
            area = IP_Res.get_ip_address(ip)
            # 返回地址

            IP_Obj = IP()
            IP_Obj.ip = ip
            IP_Obj.servers = str(servers)
            IP_Obj.host_type = host_type
            IP_Obj.alive_urls = str(alive_url)
            IP_Obj.area = area
            try:
                print(ip, servers, host_type, area)
            except Exception as e:
                print('错误代码 [34] {}'.format(str(e)))
                Error_Log.objects.create(url=url,
                                         error='错误代码 [34] {}'.format(str(e)))
            IP_Obj.save()
        except Exception as e:
            print('错误代码 [30] {}'.format(str(e)))
            Error_Log.objects.create(url=url,
                                     error='错误代码 [30] {}'.format(str(e)))
コード例 #2
0
def Change_IP_Info():
    # close_old_connections()
    time.sleep(random.randint(1, 20))
    time.sleep(random.randint(1, 20))
    time.sleep(random.randint(1, 20))
    try:
        target_ip = IP.objects.filter(get='否')[0]
        ip = target_ip.ip
        target_ip.get = '中'
        # 为了防止重复获取同一个数值,这里进行修改
        # 但是有时候 数据没有正常跑出来 设置成 【是】 会导致偏差
        target_ip.save()
    except Exception as e:
        time.sleep(600)
        # 等待并充实一次
        try:
            target_ip2 = IP.objects.filter(get='否')[0]
            ip = target_ip2.ip
            target_ip2.get = '中'
            target_ip2.save()
        except Exception as e:
            Except_Log(stat=39, url='|获取数据库 IP 资产失败|', error=str(e))
            return
    try:
        print('[+ Host Scaner] 当前扫描主机 : {}'.format(ip))
        IP_Res = Get_Ip_Info(ip)
        servers = IP_Res.get_server_from_nmap(ip)
        # 服务与端口  字典类型
        open_port = servers.keys()
        check_alive_url = []
        for port in open_port:
            check_alive_url.append('http://{}:{}'.format(ip, port))
            check_alive_url.append('https://{}:{}'.format(ip, port))
        alive_url = Get_Alive_Url(check_alive_url)
        # 该IP上存活WEB,类型为列表,内容为多个字典
        host_type = IP_Res.get_host_type(ip)
        # windows/linux
        area = IP_Res.get_ip_address(ip)
        # 返回地址
        cs = IP_Res.get_cs_name(ip)

        IP_Obj = IP.objects.filter(ip=ip)[0]
        IP_Obj.ip = ip
        IP_Obj.servers = str(servers)
        IP_Obj.host_type = host_type
        IP_Obj.alive_urls = str(alive_url)
        IP_Obj.area = area
        IP_Obj.cs = cs
        IP_Obj.get = '是'
        IP_Obj.save()
    except Exception as e:
        Except_Log(stat=53, url='|清洗 IP 资产失败|', error=str(e))
        # 这里如果失败,则回退
        IP_Obj_f = IP.objects.filter(ip=ip)[0]
        IP_Obj_f.get = '否'
        IP_Obj_f.save()
    '''
コード例 #3
0
ファイル: main.py プロジェクト: rockmelodies/LangSrcCurise
def Change_IP_Info():
    while 1:
        time.sleep(random.randint(1,20))
        time.sleep(random.randint(1,20))
        time.sleep(random.randint(1,20))
        time.sleep(random.randint(1,20))
        try:
            target_ip = IP.objects.filter(get='否')[0]
            ip = target_ip.ip
            target_ip.get = '中'
            # 为了防止重复获取同一个数值,这里进行修改
            # 但是有时候 数据没有正常跑出来 设置成 【是】 会导致偏差
            target_ip.save()
        except Exception as e:
            time.sleep(3600)
            # 等待并充实一次
            try:
                target_ip = IP.objects.filter(get='否')[0]
                ip = target_ip.ip
                target_ip.get = '中'
                target_ip.save()
            except Exception as e:
                print('错误代码 [39] {}'.format(str(e)))
                Error_Log.objects.create(url='获取 IP 失败', error='错误代码 [39] {}'.format(str(e)))
                return

        print('[+ Host Scaner] 当前扫描主机 : {}'.format(ip))
        IP_Res = Get_Ip_Info(ip)
        servers = IP_Res.get_server_from_nmap(ip)
        # 服务与端口  字典类型
        open_port = servers.keys()
        check_alive_url = []
        for port in open_port:
            check_alive_url.append('http://{}:{}'.format(ip, port))
            check_alive_url.append('https://{}:{}'.format(ip, port))
        alive_url = Get_Alive_Url(check_alive_url)
        # 该IP上存活WEB,类型为列表,内容为多个字典
        host_type = IP_Res.get_host_type(ip)
        # windows/linux
        area = IP_Res.get_ip_address(ip)
        # 返回地址
        cs = IP_Res.get_cs_name(ip)

        IP_Obj = IP.objects.filter(ip=ip)[0]
        IP_Obj.ip = ip
        IP_Obj.servers = str(servers)
        IP_Obj.host_type = host_type
        IP_Obj.alive_urls = str(alive_url)
        IP_Obj.area = area
        IP_Obj.cs = cs
        IP_Obj.get = '是'
        try:
            IP_Obj.save()
        except Exception as e:
            print('错误代码 [38] {}'.format(str(e)))
            Error_Log.objects.create(url='获取 IP 失败', error='错误代码 [38] {}'.format(str(e)))
コード例 #4
0
def Change_IP_Info():
    time.sleep(random.randint(10, 20))
    time.sleep(random.randint(10, 20))
    time.sleep(random.randint(10, 20))
    time.sleep(random.randint(10, 20))
    time.sleep(random.randint(10, 20))
    time.sleep(random.randint(10, 20))
    time.sleep(random.randint(10, 20))
    time.sleep(random.randint(10, 20))
    time.sleep(random.randint(10, 20))
    # 首先捕获一个值,设置为扫描中状态,但是要确保是事务
    try:
        target_ip = IP.objects.filter(get='否')[0]
        ip = target_ip.ip
        target_ip.get = '中'
        # 为了防止重复获取同一个数值,这里进行修改
        # 但是有时候 数据没有正常跑出来 设置成 【是】 会导致偏差
        target_ip.save()
    except Exception as e:
        time.sleep(360)
        # 等待并充实一次
        Except_Log(stat=19, url='|扫描IP资产并设置扫描状态失败|', error='获取预扫描IP失败')
        return

    try:
        print('[+ Host Scaner] 当前扫描主机 : {}'.format(ip))
        IP_Res = Get_Ip_Info(ip)
        servers = IP_Res.get_server_from_nmap(ip)
        # 服务与端口  字典类型
        open_port = servers.keys()
        check_alive_url = []
        for port in open_port:
            check_alive_url.append('{}:{}'.format(ip, port))
        alive_url = Get_Alive_Url(check_alive_url)
        # 该IP上存活WEB,类型为列表,内容为多个字典
        host_type = IP_Res.get_host_type(ip)
        # windows/linux
        area = IP_Res.get_ip_address(ip)
        # 返回地址
        cs = IP_Res.get_cs_name(ip)

        IP_Obj_ip = ip
        IP_Obj_servers = str(servers)
        IP_Obj_host_type = host_type
        IP_Obj_alive_urls = str(alive_url)
        IP_Obj_area = area
        IP_Obj_cs = cs
        IP_Obj_get = '是'
        try:
            IP_Obj = IP.objects.filter(ip=ip)[0]
            IP_Obj.ip = IP_Obj_ip
            IP_Obj.host_type = IP_Obj_host_type
            IP_Obj.alive_urls = IP_Obj_alive_urls
            IP_Obj.servers = IP_Obj_servers
            IP_Obj.area = IP_Obj_area
            IP_Obj.cs = IP_Obj_cs
            IP_Obj.get = IP_Obj_get
            IP_Obj.save()
        except:
            # 这里重试的原因是有可能因为失去链接导致无法保存
            # 但是扫描ip是耗时操作,获取的数据不能轻易的舍弃,重试一次
            try:
                close_old_connections()
                IP_Obj = IP.objects.filter(ip=ip)[0]
                IP_Obj.ip = IP_Obj_ip
                IP_Obj.host_type = IP_Obj_host_type
                IP_Obj.alive_urls = IP_Obj_alive_urls
                IP_Obj.servers = IP_Obj_servers
                IP_Obj.area = IP_Obj_area
                IP_Obj.cs = IP_Obj_cs
                IP_Obj.get = IP_Obj_get
                IP_Obj.save()
            except:
                # 还是无法保存到数据库,直接回滚状态
                close_old_connections()
                IP_Obj_fx = IP.objects.filter(ip=ip)[0]
                IP_Obj_fx.get = '否'
                IP_Obj_fx.save()
    except Exception as e:
        Except_Log(stat=28, url=ip + '|清洗 IP 资产失败|', error=str(e))
        # 这里如果失败,则回退
        close_old_connections()
        IP_Obj_f = IP.objects.filter(ip=ip)[0]
        IP_Obj_f.get = '否'
        IP_Obj_f.save()
    '''