def get_result(domain_punycode, tld, whois_addr, func_name, data, flag): """ :param domain_punycode: punycode格式的域名 :param tld: 顶级域 :param whois_addr: whois服务器 :param func_name: 处理函数 :param data: 服务器返回数据 :param flag: 数据正确性标记位 :return: whois 信息字典 """ # 返回结果初始化 domain_whois = { "domain": str(domain_punycode), # 域名 "tld": tld, # 顶级域 "flag": flag, # 状态标记 "domain_status": "", # 域名状态 "sponsoring_registrar": "", # 注册商 "top_whois_server": whois_addr, # 顶级域名服务器 "sec_whois_server": "", # 二级域名服务器 "reg_name": "", # 注册姓名 "reg_phone": "", # 注册电话 "reg_email": "", # 注册email "org_name": "", # 注册公司名称 "creation_date": "", # 创建时间 "expiration_date": "", # 到期时间 "updated_date": "", # 更新时间 "details": data, # 细节 "name_server": "", # 域名服务器 } if domain_whois['flag'] < 0: # 错误数据直接返回 粗处理结果,不调用提取函数 return domain_whois # 处理原始whois数据 if func_name == 'com_manage': # 针对com,net 等具有二级服务器的域名进行特殊处理 # 1,处理含有 'xxx='的情况 whois_details_first = data if xxx_bool(whois_details_first): try: whois_details_first = GetWhoisInfo('=' + domain_punycode, whois_addr).get() except WhoisConnectException as connect_error: # 二级whois解析过程错误记录 domain_whois['flag'] = 0 - int(str(connect_error)) # 2,处理二级whois服务器 whois_details_sec = None try: whois_server_sec = get_sec_server(whois_details_first, domain_punycode) if whois_server_sec: # 如果获取到了二级whois地址,更新sec_whois并重新获取数据 domain_whois['sec_whois_server'] = whois_server_sec whois_details_sec = GetWhoisInfo(domain_punycode, whois_server_sec).get() if whois_details_sec is not None: domain_whois['details'] = whois_details_sec except WhoisConnectException as connect_error: # 二级whois解析过程错误记录 domain_whois['flag'] = -10 - int(str(connect_error)) try: # 处理 detail 项中的引号,用于SQL语句 删除多余的'/' domain_whois['details'] = domain_whois['details'].replace("\\", "") domain_whois['details'] = domain_whois['details'].replace("'", " \\'") domain_whois['details'] = domain_whois['details'].replace('"', ' \\"') # 使用提取函数处理whois获取字典 data = domain_whois['details'] domain_whois = eval( '{func}(data, domain_whois)'.format(func=func_name)) except Exception as e: log_func.error(domain_punycode + '->' + func_name + ' 提取函数处理失败 ' + str(e)) # 处理状态值 domain_whois['domain_status'] = get_status_value( domain_whois['domain_status']) return domain_whois
data = get_recv_info(domain, whois_server) print '-------------------data---------------------' print data if not data: exit() print "---------------domain_whois-----------------" #general_manage result = be_manage(data, domain_whois) #result = general_manage(data, domain_whois) result['insert_time'] = str(datetime.datetime.now()) result = flag_manage(result) result['status'] = domain_status.get_status_value(domain_whois['status'], domain_whois['domain']) result['hash_value'] = hash(domain_whois['details']) print "domain: ", result['domain'] print "status: ", result['status'] print "flag: ", result['flag'] print "sponsoring_registrar: ", result['sponsoring_registrar'] print "top_whois_server: ", result['top_whois_server'] print "sec_whois_server: ", result['sec_whois_server'] print "reg_name: ", result['reg_name'] print "reg_phone: ", result['reg_phone'] print "reg_email: ", result['reg_email'] print "org_name: ", result['org_name'] print "updated_date: ", result['updated_date'] print "creation_date: ", result['creation_date'] print "expiration_date: ", result['expiration_date']
def get_result(domain_punycode, tld, whois_addr, func_name, data, flag): """ :param domain_punycode: punycode格式的域名 :param tld: 顶级域 :param whois_addr: whois服务器 :param func_name: 处理函数 :param data: 服务器返回数据 :param flag: 数据正确性标记位 :return: whois 信息字典 """ # 返回结果初始化 domain_whois = { "domain": str(domain_punycode), # 域名 "tld": tld, # 顶级域 "flag": flag, # 状态标记 "domain_status": "", # 域名状态 "sponsoring_registrar": "", # 注册商 "top_whois_server": whois_addr, # 顶级域名服务器 "sec_whois_server": "", # 二级域名服务器 "reg_name": "", # 注册姓名 "reg_phone": "", # 注册电话 "standard_phone": "", # 标准电话 "phone_country_code": "", # 电话国家 "phone_position_code": "", # 地话地域 "phone_number": "", # 纯电话 "phone_type": 0, # 电话长度 "reg_email": "", # 注册email "org_name": "", # 注册公司名称 "creation_date": "", # 创建时间 "expiration_date": "", # 到期时间 "updated_date": "", # 更新时间 "details": data, # 细节 "name_server": "", # 域名服务器 } if domain_whois['flag'] < 0: # ,错误数据直接返回 粗处理结果不调用提取函数 return domain_whois whois_details_first = data whois_details_sec = '' # 处理原始whois数据 if func_name == 'com_manage': # 针对com,net 等具有二级服务器的域名进行特殊处理 # 1,处理含有 'xxx='的情况 whois_details_first = data if xxx_bool(whois_details_first): whois_details_first = GetWhoisInfo('=' + domain_punycode, whois_addr).get() if whois_details_first.startswith('Socket Error'): domain_whois['flag'] = -1 # WHOIS服务器交互过程中出现异常 flag > -1 elif whois_details_first == '': domain_whois['flag'] = -5 # 获取到空数据,flag = -5 # 2,处理二级whois服务器 if domain_whois['flag'] < 0: # 错误数据直接返回 粗处理结果不调用提取函数 return domain_whois whois_server_sec = get_sec_server(whois_details_first, domain_punycode) if whois_server_sec: # 如果获取到了二级whois地址,更新sec_whois并重新获取数据 domain_whois['sec_whois_server'] = whois_server_sec whois_details_sec = GetWhoisInfo(domain_punycode, whois_server_sec).get() if whois_details_sec.startswith('Socket Error') or whois_details_sec.startswith('Your request') or \ whois_details_sec.startswith('WHOIS LIMIT EXCEEDED') or whois_details_sec.startswith('interval') or\ whois_details_sec.startswith('IP Address') or whois_details_sec.startswith('ERROR') or \ whois_details_sec.startswith('You') or whois_details_sec.startswith('The query') or \ whois_details_sec.startswith('The IP') or whois_details_sec.startswith('We are unable'): domain_whois['flag'] = -2 # 二级WHOIS服务器交互过程中出现异常 flag > -2 elif whois_details_sec == '': domain_whois['flag'] = -4 # 二级WHOIS服务器返回空数据,flag > -4 else: domain_whois['flag'] = -3 # 没有获取到二级WHOIS服务器 flag > -3 # 处理 detail 项中的引号,用于SQL语句 删除多余的 / ' " whois_details_first = whois_details_first.replace("\\", "").replace("'", " \\'").replace('"', ' \\"') domain_whois['details'] = whois_details_first if whois_details_sec: whois_details_sec = whois_details_sec.replace("\\", "").replace("'", " \\'").replace('"', ' \\"') domain_whois['details'] += "\n##############################\n\n" + \ whois_details_sec try: # 使用提取函数处理whois获取字典 依次解析一级/二级WHOIS数据 domain_whois = eval('{func}(whois_details_first, domain_whois)'.format(func=func_name)) if whois_details_sec: sec_domain_whois = copy.deepcopy(domain_whois) # 这里一定要是深复制,否则会改变原始的内容 sec_domain_whois = eval('{func}(whois_details_sec, sec_domain_whois)'.format(func=func_name)) # 合并字典 for k in sec_domain_whois.keys(): # 只更新部分字段 if k in ["sponsoring_registrar", "sec_whois_server", "reg_name", "reg_phone", "reg_email", "org_name", "creation_date", "expiration_date", "updated_date", "name_server"]: if sec_domain_whois[k].strip(): domain_whois[k] = sec_domain_whois[k] except Exception as e: log_func.error(domain_punycode + '->' + func_name + ' 提取函数处理失败 ' + str(e)) # 处理状态值、标准时间、电话 domain_whois['domain_status'] = get_status_value(domain_whois['domain_status']) domain_whois['creation_date'] = format_timestamp(domain_whois['creation_date']) domain_whois['expiration_date'] = format_timestamp(domain_whois['expiration_date']) domain_whois['updated_date'] = format_timestamp(domain_whois['updated_date']) return domain_whois
domain_whois['top_whois_server'] = whois_server data = get_recv_info(domain, whois_server) print '-------------------data---------------------' print data if not data: exit() print "---------------domain_whois-----------------" result = data_deal(data, domain_whois) result['insert_time'] = str(datetime.datetime.now()).split('.')[1] result['flag'] = flag_manage(result) result['details'] = str(data) result['domain_status'] = get_status_value(result['domain_status'], result['domain']) result['hash_value'] = hash(result['details']) print "domain: ", result['domain'] print "domain_status: ", result['domain_status'] print "flag: ", result['flag'] print "sponsoring_registrar: ", result['sponsoring_registrar'] print "top_whois_server: ", result['top_whois_server'] print "sec_whois_server: ", result['sec_whois_server'] print "reg_name: ", result['reg_name'] print "reg_phone: ", result['reg_phone'] print "reg_email: ", result['reg_email'] print "org_name: ", result['org_name'] print "updated_date: ", result['updated_date'] print "creation_date: ", result['creation_date'] print "expiration_date: ", result['expiration_date']