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