python - socket.gaierror: [Ernno 1104] -
i'm trying make ip resolver website using gethostbyname , error get:
file "wexec.py", line 39, in hell ipname = socket.gethostbyname('http://%s') % (hcon) socket.gaierror: [errno 11004] getaddrinfo failed i have attempted fix , tried putting ('www.youtube.com') , worked. i'm not sure i'm doing wrong. here code:
def hell(): hcon = raw_input(fore.red + style.bright + "website: ") urlopen = urllib2.urlopen('http://%s:80' % (hcon)) ipname = socket.gethostbyname('http://%s') % (hcon) print(strftime("[%h:%m:%s]", gmtime()) + " found ip: %s " % (ipname)) enter = raw_input("press enter or other key continue.") hell() so do? can help?
for start, bracketing off. rather than:
ipname = socket.gethostbyname('http://%s') % (hcon) it should be:
ipname = socket.gethostbyname('http://%s' % (hcon)) by closing call gethostbyname early, prevented %s string formatting taking place, meaning name contained literal %s rather value of hcon.
i'm not sure should including http:// in host name either. hostname not same url. want remove url type front, in case may simplify to:
ipname = socket.gethostbyname(hcon)
Comments
Post a Comment