01.
using
System;
02.
using
System.Drawing;
03.
using
System.Net;
04.
using
System.Text;
05.
using
System.Windows.Forms;
06.
class
AsyncResolve Form:
07.
{
08.
TextBox address;
09.
ListBox results;
10.
private
AsyncCallback OnResolved;
11.
public
AsyncResolve()
12.
{
13.
Text =
"DNS Address Resolver"
;
14.
Size =
new
Size(400,380);
15.
OnResolved =
new
AsyncCallback(Resolved);
16.
Label label1 =
new
Label();
17.
label1.Parent =
this
;
18.
label1.Text =
"Enter address to resolve:"
;
19.
label1.AutoSize =
true
;
20.
label1.Location =
new
Point(10, 10);
21.
address =
new
TextBox();
22.
address.Parent =
this
;
23.
address.Size =
new
Size(200, 2 * Font.Height);
24.
address.Location =
new
Point(10, 35);
25.
results =
new
ListBox();
26.
results.Parent =
this
;
27.
results.Location =
new
Point(10, 65);
28.
results.Size =
new
Size(350, 20 * Font.Height);
29.
Button checkit =
new
Button();
30.
checkit.Parent =
this
;
31.
checkit.Text =
"Resolve"
;
32.
checkit.Location =
new
Point(235,32);
33.
checkit.Size =
new
Size(7 * Font.Height, 2 * Font.Height);
34.
checkit.Click +=
new
EventHandler(ButtonResolveOnClick);
35.
}
36.
void
ButtonResolveOnClick(
object
obj, EventArgs ea)
37.
{
38.
results.Items.Clear();
39.
string
addr = address.Text;
40.
Object state =
new
Object();
41.
Dns.BeginResolve(addr, OnResolved, state);
42.
}
43.
private
void
Resolved(IAsyncResult ar)
44.
{
45.
string
buffer;
46.
IPHostEntry iphe = Dns.EndResolve(ar);
47.
buffer =
"Host name: "
+ iphe.HostName;
48.
results.Items.Add(buffer);
49.
foreach
(
string
alias
in
iphe.Aliases)
50.
{
51.
buffer =
"Alias: "
+ alias;
52.
results.Items.Add(buffer);
53.
}
54.
foreach
(IPAddress addrs
in
iphe.AddressList)
55.
{
56.
buffer =
"Address: "
+ addrs.ToString();
57.
results.Items.Add(buffer);
58.
}
59.
}
60.
public
static
void
Main()
61.
{
62.
Application.Run(
new
AsyncResolve());
63.
}
64.
}