socket.gethostbyname [Errno -2] 名称或服务未知
socket.gethostbyname [Errno -2] Name or service not known
我试图检查几个域名,但即使是一些常见的域名也会返回这个
错误发生在“df['IPaddr'] = socket.gethostbyname(DN)”
socket.gethostbyname [Errno -2] 名称或服务未知
所以我尝试了:但是大多数都失败了!
检查域
意外错误:
AMD.com
意外错误:
AOL.com
import whois
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import socket
import os
import csv
import datetime
import time
import requests
from ipwhois import IPWhois
from urllib import request
from ipwhois.utils import get_countries
import tldextract
from ipwhois.utils import get_countries
countries = get_countries(is_legacy_xml=True)
from ipwhois.experimental import bulk_lookup_rdap
from ipwhois.hr import (HR_ASN, HR_ASN_ORIGIN, HR_RDAP_COMMON, HR_RDAP, HR_WHOIS, HR_WHOIS_NIR)
countries = get_countries(is_legacy_xml=True)
import ipaddress
df = pd.read_csv('a.csv')
#TimeOut Setting
s = socket.socket()
s.settimeout(10)
#Date Processing Function
def check_date_type(d):
if type(d) is datetime.datetime:
return d
if type(d) is list:
return d[0]
for index,row in df.iterrows():
try:
allow_permutations=True
看起来不像是 IPWhois
的有效参数。因为您使用的是 try
,您可能看不到 TypeError:
TypeError: __init__() got an unexpected keyword argument 'allow_permutations'
删除该参数后,一切正常:
from ipwhois import IPWhois
import socket
DN = 'AMD.com'
ip = socket.gethostbyname(DN)
ipwhois = IPWhois(ip).lookup_whois()
print(ip)
print(ipwhois)
23.50.124.85
{'nir': None, 'asn_registry': 'arin', 'asn': '16625', 'asn_cidr': '23.50.124.0/22', 'asn_country_code': 'US', 'asn_date': '2011-05-16', 'asn_description': 'AKAMAI-AS, US', 'query': '23.50.124.85', 'nets': [{'cidr': '23.32.0.0/11, 23.64.0.0/14', 'name': 'AKAMAI', 'handle': 'NET-23-32-0-0-1', 'range': '23.32.0.0 - 23.67.255.255', 'description': 'Akamai Technologies, Inc.', 'country': 'US', 'state': 'MA', 'city': 'Cambridge', 'address': '145 Broadway', 'postal_code': '02142', 'emails': ['ip-admin@akamai.com', 'abuse@akamai.com'], 'created': '2011-05-16', 'updated': '2012-03-02'}], 'raw': None, 'referral': None, 'raw_referral': None}
如果您仍然遇到问题,可能是 DNS 或路由问题导致了问题。一种快速隔离您的本地环境是否是问题的方法是在 Google Colab 之类的东西中测试您的代码片段,因为运行时将在 Google 服务器上:https://colab.research.google.com/
如果这些建议都不起作用,您最好删除 try 语句或将异常打印到控制台并 post 您在此处收到的错误:
try:
ip = socket.gethostbyname(DN)
ipwhois = IPWhois(ip, allow_permutations=True).lookup_whois()
print(ip)
print(ipwhois)
except Exception as e:
print(e)
我试图检查几个域名,但即使是一些常见的域名也会返回这个
错误发生在“df['IPaddr'] = socket.gethostbyname(DN)”
socket.gethostbyname [Errno -2] 名称或服务未知
所以我尝试了:但是大多数都失败了!
检查域
意外错误:
AMD.com
意外错误:
AOL.com
import whois
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import socket
import os
import csv
import datetime
import time
import requests
from ipwhois import IPWhois
from urllib import request
from ipwhois.utils import get_countries
import tldextract
from ipwhois.utils import get_countries
countries = get_countries(is_legacy_xml=True)
from ipwhois.experimental import bulk_lookup_rdap
from ipwhois.hr import (HR_ASN, HR_ASN_ORIGIN, HR_RDAP_COMMON, HR_RDAP, HR_WHOIS, HR_WHOIS_NIR)
countries = get_countries(is_legacy_xml=True)
import ipaddress
df = pd.read_csv('a.csv')
#TimeOut Setting
s = socket.socket()
s.settimeout(10)
#Date Processing Function
def check_date_type(d):
if type(d) is datetime.datetime:
return d
if type(d) is list:
return d[0]
for index,row in df.iterrows():
try:
allow_permutations=True
看起来不像是 IPWhois
的有效参数。因为您使用的是 try
,您可能看不到 TypeError:
TypeError: __init__() got an unexpected keyword argument 'allow_permutations'
删除该参数后,一切正常:
from ipwhois import IPWhois
import socket
DN = 'AMD.com'
ip = socket.gethostbyname(DN)
ipwhois = IPWhois(ip).lookup_whois()
print(ip)
print(ipwhois)
23.50.124.85
{'nir': None, 'asn_registry': 'arin', 'asn': '16625', 'asn_cidr': '23.50.124.0/22', 'asn_country_code': 'US', 'asn_date': '2011-05-16', 'asn_description': 'AKAMAI-AS, US', 'query': '23.50.124.85', 'nets': [{'cidr': '23.32.0.0/11, 23.64.0.0/14', 'name': 'AKAMAI', 'handle': 'NET-23-32-0-0-1', 'range': '23.32.0.0 - 23.67.255.255', 'description': 'Akamai Technologies, Inc.', 'country': 'US', 'state': 'MA', 'city': 'Cambridge', 'address': '145 Broadway', 'postal_code': '02142', 'emails': ['ip-admin@akamai.com', 'abuse@akamai.com'], 'created': '2011-05-16', 'updated': '2012-03-02'}], 'raw': None, 'referral': None, 'raw_referral': None}
如果您仍然遇到问题,可能是 DNS 或路由问题导致了问题。一种快速隔离您的本地环境是否是问题的方法是在 Google Colab 之类的东西中测试您的代码片段,因为运行时将在 Google 服务器上:https://colab.research.google.com/
如果这些建议都不起作用,您最好删除 try 语句或将异常打印到控制台并 post 您在此处收到的错误:
try:
ip = socket.gethostbyname(DN)
ipwhois = IPWhois(ip, allow_permutations=True).lookup_whois()
print(ip)
print(ipwhois)
except Exception as e:
print(e)