9 # Definitions for our resources
18 macresource
.need("DLOG", ID_MAIN
, "dnslookup-2.rsrc")
21 class DNSLookup(FrameWork
.Application
):
22 "Application class for DNS Lookup"
25 # First init menus, etc.
26 FrameWork
.Application
.__init
__(self
)
27 # Next create our dialog
28 self
.main_dialog
= MyDialog(self
)
30 self
.main_dialog
.open(ID_MAIN
)
31 # Finally, go into the event loop
34 def makeusermenus(self
):
35 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
36 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
38 def quit(self
, *args
):
41 def do_about(self
, *args
):
42 f
= Dlg
.GetNewDialog(ID_ABOUT
, -1)
44 n
= Dlg
.ModalDialog(None)
48 class MyDialog(FrameWork
.DialogWindow
):
49 "Main dialog window for DNSLookup"
50 def __init__(self
, parent
):
51 FrameWork
.DialogWindow
.__init
__(self
, parent
)
54 def do_itemhit(self
, item
, event
):
55 if item
== ITEM_LOOKUP_BUTTON
:
59 """Get text entered in the lookup entry area. Place result of the
60 call to dnslookup in the result entry area."""
61 tp
, h
, rect
= self
.dlg
.GetDialogItem(ITEM_LOOKUP_ENTRY
)
62 txt
= Dlg
.GetDialogItemText(h
)
64 tp
, h
, rect
= self
.dlg
.GetDialogItem(ITEM_RESULT
)
65 Dlg
.SetDialogItemText(h
, self
.dnslookup(txt
))
67 def dnslookup(self
, str):
68 """ Perform DNS lookup on str. If first character of digit is numeric,
69 assume that str contains an IP address. Otherwise, assume that str
70 contains a hostname."""
71 if str == '': str = ' '
72 if str[0] in string
.digits
:
74 value
= socket
.gethostbyaddr(str)[0]
76 value
= 'Lookup failed'
79 value
= socket
.gethostbyname(str)
81 value
= 'Lookup failed'