9 # Definitions for our resources
19 dummy
= Res
.GetResource('DLOG', ID_MAIN
)
22 Res
.FSpOpenResFile("dnslookup-2.rsrc", 1)
24 EasyDialogs
.Message("Cannot open dnslookup-2.rsrc")
28 class DNSLookup(FrameWork
.Application
):
29 "Application class for DNS Lookup"
32 # First init menus, etc.
33 FrameWork
.Application
.__init
__(self
)
34 # Next create our dialog
35 self
.main_dialog
= MyDialog(self
)
37 self
.main_dialog
.open(ID_MAIN
)
38 # Finally, go into the event loop
41 def makeusermenus(self
):
42 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
43 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
45 def quit(self
, *args
):
48 def do_about(self
, *args
):
49 f
= Dlg
.GetNewDialog(ID_ABOUT
, -1)
51 n
= Dlg
.ModalDialog(None)
55 class MyDialog(FrameWork
.DialogWindow
):
56 "Main dialog window for DNSLookup"
57 def __init__(self
, parent
):
58 FrameWork
.DialogWindow
.__init
__(self
, parent
)
61 def do_itemhit(self
, item
, event
):
62 if item
== ITEM_LOOKUP_BUTTON
:
66 """Get text entered in the lookup entry area. Place result of the
67 call to dnslookup in the result entry area."""
68 tp
, h
, rect
= self
.dlg
.GetDialogItem(ITEM_LOOKUP_ENTRY
)
69 txt
= Dlg
.GetDialogItemText(h
)
71 tp
, h
, rect
= self
.dlg
.GetDialogItem(ITEM_RESULT
)
72 Dlg
.SetDialogItemText(h
, self
.dnslookup(txt
))
74 def dnslookup(self
, str):
75 """ Perform DNS lookup on str. If first character of digit is numeric,
76 assume that str contains an IP address. Otherwise, assume that str
77 contains a hostname."""
78 if str == '': str = ' '
79 if str[0] in string
.digits
:
81 value
= socket
.gethostbyaddr(str)[0]
83 value
= 'Lookup failed'
86 value
= socket
.gethostbyname(str)
88 value
= 'Lookup failed'