我用python编写了一个简单的程序,它允许您找到URL的IP地址。我得到了这个错误:
File "wexec.py", line 40, in hell
ipname = socket.gethostbyname('http://%s' % (hcon))
socket.gaierror: [Errno 11004] getaddrinfo failed现在我不确定我做错了什么,但下面是我的函数代码:
def hell():
hcon = raw_input(Fore.RED + Style.BRIGHT + "Website: ")
h1 = httplib.HTTPConnection('http://%s:80' % (hcon))
urlopen = urllib.urlopen('http://%s:80' % (hcon))
ipname = socket.gethostbyname('http://%s' % (hcon))
print(strftime("[%H:%M:%S]", gmtime()) + " Found IP: %d " % (ipname))
enter = raw_input("Press enter or any other key to continue.")
hell()如你所见。我打开一个到网站的HTTP连接,然后我用urllibb打开URL,然后我得到网站的IP。但如你所见,我不确定我做错了什么。有人能帮帮忙吗?
发布于 2013-08-01 06:15:20
socket.gethostbyname()只接受域名,因此您需要从该调用中删除'http://‘。我不明白对httplib和urllib的调用是做什么的,但是从这段代码中看起来它们是不必要的。
https://stackoverflow.com/questions/17979110
复制相似问题