0
from Tkinter import *
import tkMessageBox, socket


root = Tk()
root.title("pynet v1.0")
root.config(bg='black')
root.resizable(0,0)   

text = Text()   
text1 = Text()

text1.config(width=15, height=1)
text1.config(bg="white", fg="red")
text1.pack()

def Info():
    targetip = socket.gethostbyname_ex(text1.get("1.0", END))
    text.insert(END, targetip)

b = Button(root, text="Enter", width=10, height=2, command=Info)
b.config(fg="black", bg="red")
b.pack(side=TOP, padx=5)

scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
text.config(width=25, height=5, bg="white", fg="red")
text.pack(side=LEFT, fill=Y)
scrollbar.config(command=text.yview)
text.config(yscrollcommand=scrollbar.set)

root.mainloop()

I'm trying to retrieve the IP Address of a website, but I keep getting this error, "gaierror: [Errno 11004] getaddrinfo failed" in line 18, your help will be appreciated, Thanks.

The Error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "C:\Users\Rabia\Desktop\gethostinfo.py", line 18, in Info
    targetip = socket.gethostbyname_ex(text1.get("1.0", END))
gaierror: [Errno 11004] getaddrinfo failed
SourD
  • 2,771
  • 7
  • 28
  • 28
  • So that no one else has to count it out, line 19 is `targetip = socket.gethostbyname_ex(text1.get("1.0", END) + "\r\n")` – Rafe Kettler Nov 08 '10 at 17:10
  • You have to get rid of the first wild import `from socket import *`. It does nothing except hurt performance and mess up the namespace. That probably won't solve your problem – Rafe Kettler Nov 08 '10 at 17:17

2 Answers2

2

My guess is because you are using a hostname that has a trailing newline. At the time I write this answer, your code shows:

def Info():
    targetip = socket.gethostbyname_ex(text1.get("1.0", END))
    text.insert(END, targetip)

When you use the index END you get the extra newline that is added by the text widget. You need to strip that off or use the index "end-1c".

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
1

Why are you adding CRLF (\r\n) to the hostname before looking it up?

If removing that doesn't fix it, print out the exact text you're passing to gethostbyname to make sure it's a valid hostname.

Ben Jackson
  • 90,079
  • 9
  • 98
  • 150
  • Yeah I forgot to delete the (\r\n) sorry about that. I'm just typing in random websites, like msn.com, google.com, and nothing works. – SourD Nov 08 '10 at 17:33
  • Also, by using the index END you're getting a newline as the host name – Bryan Oakley Nov 08 '10 at 18:23