0

我正在用 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。但正如你所看到的,我不确定我做错了什么。有人可以帮忙吗?

4

1 回答 1

2

socket.gethostbyname() 只接受域名,因此您需要从该调用中删除“http://”。我不明白对 httplib 和 urllib 的调用在做什么,但从这段代码中它们似乎是不必要的。

于 2013-07-31T22:15:19.637 回答