Ejemplo n.º 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)))
Ejemplo n.º 2
0
def lookup(ip_addr):
    url = f"http://www.geoplugin.net/json.gp?ip={ip_addr}"
    try:
        response = requests.get(url)
        if response.status_code != 200:
            logging.error("%s replyed with a not ok status code", url)
            return ""

        new_ip = IP()
        new_ip.insert_raw(response.json())
        new_ip.save()
        return new_ip
    except ConnectionError:
        logging.error("failed to fetch api details for %s", url)
        return ""
Ejemplo n.º 3
0
 def test_insert(self):
     new_ip = IP()
     new_ip.insert_raw(APIRESPONSE)
     new_ip.save()
Ejemplo n.º 4
0
# This is so my local_settings.py gets loaded.
os.chdir(proj_path)

# This is so models get loaded.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
from app.models import IP

txtreader = open("time.txt",'r')
readtmp = "app/result/" + txtreader "ping.txt"
dataReader = csv.reader(open(readtmp), delimiter=',')

for row in dataReader:
    if row[0] != 'Date/Time': # Ignore the header row, import everything else
        ping = IP()
        ping.date = row[0]
        ping.site = row[1]
        ping.tunName = row[2]
        ping.tunType = row[3]
        ping.ip = row[4]
        ping.reach = row[5]

        dtexists = IP.objects.filter(date__iexact = ping.date).exists()
        diexists = IP.objects.filter(ip__iexact = ping.ip).exists()

        if not diexists:
                ping.save()
        else:
            pass