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