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