markus / DnsCheckTest / MainWindow.xaml.cs @ ab590000
이력 | 보기 | 이력해설 | 다운로드 (3.15 KB)
1 |
using Newtonsoft.Json; |
---|---|
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.Linq; |
5 |
using System.Net; |
6 |
using System.Net.NetworkInformation; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
using System.Windows; |
10 |
using System.Windows.Controls; |
11 |
using System.Windows.Data; |
12 |
using System.Windows.Documents; |
13 |
using System.Windows.Input; |
14 |
using System.Windows.Media; |
15 |
using System.Windows.Media.Imaging; |
16 |
using System.Windows.Navigation; |
17 |
using System.Windows.Shapes; |
18 |
|
19 |
namespace DnsCheckTest |
20 |
{ |
21 |
/// <summary> |
22 |
/// MainWindow.xaml에 대한 상호 작용 논리 |
23 |
/// </summary> |
24 |
public partial class MainWindow : Window |
25 |
{ |
26 |
public MainWindow() |
27 |
{ |
28 |
InitializeComponent(); |
29 |
|
30 |
DnsCheckOld(); |
31 |
DnsCheck(); |
32 |
} |
33 |
|
34 |
private void Button_Click(object sender, RoutedEventArgs e) |
35 |
{ |
36 |
DnsCheckOld(); |
37 |
DnsCheck(); |
38 |
} |
39 |
|
40 |
private void DnsCheck() |
41 |
{ |
42 |
var host = CommonLib.DNSHelper.GetHostEntryTask(); |
43 |
|
44 |
StringBuilder builder = new StringBuilder(); |
45 |
|
46 |
builder.AppendLine($"hostName : {host.HostName}"); |
47 |
|
48 |
builder.AppendLine(""); |
49 |
builder.AppendLine(" - Aliases"); |
50 |
|
51 |
foreach (var item in host.Aliases) |
52 |
{ |
53 |
builder.AppendLine($" {item}"); |
54 |
} |
55 |
|
56 |
builder.AppendLine(""); |
57 |
builder.AppendLine(" - Address List"); |
58 |
|
59 |
foreach (var item in host.AddressList) |
60 |
{ |
61 |
builder.AppendLine($" {item.AddressFamily.ToString()} : {item.ToString()}"); |
62 |
} |
63 |
|
64 |
txtHostInfo.Text = builder.ToString(); |
65 |
} |
66 |
|
67 |
private void DnsCheckOld() |
68 |
{ |
69 |
var ipaddress = GetDnsAdress(); |
70 |
|
71 |
StringBuilder builder = new StringBuilder(); |
72 |
|
73 |
var host = Dns.GetHostEntry(ipaddress); |
74 |
|
75 |
builder.AppendLine($"hostName : {host.HostName}"); |
76 |
|
77 |
builder.AppendLine(""); |
78 |
builder.AppendLine(" - Aliases"); |
79 |
|
80 |
foreach (var item in host.Aliases) |
81 |
{ |
82 |
builder.AppendLine($" {item}"); |
83 |
} |
84 |
|
85 |
builder.AppendLine(""); |
86 |
builder.AppendLine(" - Address List"); |
87 |
|
88 |
foreach (var item in host.AddressList) |
89 |
{ |
90 |
builder.AppendLine($" {item.AddressFamily.ToString()} : {item.ToString()}"); |
91 |
} |
92 |
|
93 |
txtHostInfoOld.Text = builder.ToString(); |
94 |
} |
95 |
|
96 |
public static IPAddress GetDnsAdress() |
97 |
{ |
98 |
NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); |
99 |
|
100 |
foreach (NetworkInterface networkInterface in networkInterfaces) |
101 |
{ |
102 |
if (networkInterface.OperationalStatus == OperationalStatus.Up) |
103 |
{ |
104 |
IPInterfaceProperties ipProperties = networkInterface.GetIPProperties(); |
105 |
IPAddressCollection dnsAddresses = ipProperties.DnsAddresses; |
106 |
|
107 |
foreach (IPAddress dnsAdress in dnsAddresses) |
108 |
{ |
109 |
return dnsAdress; |
110 |
} |
111 |
} |
112 |
} |
113 |
return null; |
114 |
} |
115 |
} |
116 |
} |