-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathResolutionTester.cs
More file actions
64 lines (55 loc) · 1.7 KB
/
ResolutionTester.cs
File metadata and controls
64 lines (55 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
namespace HostsManager
{
public partial class ResolutionTester : Form
{
public ResolutionTester()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
String hostname = textBox1.Text;
label2.ForeColor = Color.Black;
label2.Text = "Resolving " + hostname + "...";
Dns.BeginGetHostEntry(hostname, onResolveResult, hostname);
}
private void onResolveResult(IAsyncResult result)
{
IPHostEntry dnsEntry = null;
try
{
dnsEntry = Dns.EndGetHostEntry(result);
}
catch (Exception e) { }
string inHostname = (String)result.AsyncState;
this.BeginInvoke(new Action(() =>
{
if (dnsEntry == null || dnsEntry.AddressList.Length == 0)
{
label2.Text = "Could not resolve " + inHostname;
}
else
{
if (dnsEntry.HostName != inHostname)
{
inHostname = inHostname + " (" + dnsEntry.HostName + ")";
}
label2.Text = inHostname + " resolves to " + dnsEntry.AddressList[0];
}
}));
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
button2.Enabled = textBox1.TextLength > 0;
}
}
}