1 """Sample program performing domain name lookups and showing off EasyDialogs,
2 Res and Dlg in the process"""
11 # Definitions for our resources
20 """Main routine: open resource file, call dialog handler"""
21 macresource
.need("DLOG", ID_MAIN
, "dnslookup-1.rsrc")
25 """Post dialog and handle user interaction until quit"""
26 my_dlg
= Dlg
.GetNewDialog(ID_MAIN
, -1)
28 n
= Dlg
.ModalDialog(None)
29 if n
== ITEM_LOOKUP_BUTTON
:
30 tp
, h
, rect
= my_dlg
.GetDialogItem(ITEM_LOOKUP_ENTRY
)
31 txt
= Dlg
.GetDialogItemText(h
)
33 tp
, h
, rect
= my_dlg
.GetDialogItem(ITEM_RESULT
)
34 Dlg
.SetDialogItemText(h
, dnslookup(txt
))
35 elif n
== ITEM_QUIT_BUTTON
:
39 """ Perform DNS lookup on str. If first character of digit is numeric,
40 assume that str contains an IP address. Otherwise, assume that str
41 contains a hostname."""
42 if str == '': str = ' '
43 if str[0] in string
.digits
:
45 value
= socket
.gethostbyaddr(str)[0]
47 value
= 'Lookup failed'
50 value
= socket
.gethostbyname(str)
52 value
= 'Lookup failed'