프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / DnsCheckTest / MainWindow.xaml.cs @ 4d2c8ee1

이력 | 보기 | 이력해설 | 다운로드 (3.15 KB)

1 43bbd277 taeseongkim
using Newtonsoft.Json;
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5 f280a4ce taeseongkim
using System.Net;
6
using System.Net.NetworkInformation;
7 43bbd277 taeseongkim
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 f280a4ce taeseongkim
            DnsCheckOld();
31 43bbd277 taeseongkim
            DnsCheck();
32
        }
33
34
        private void Button_Click(object sender, RoutedEventArgs e)
35
        {
36 f280a4ce taeseongkim
            DnsCheckOld();
37 43bbd277 taeseongkim
            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 f280a4ce taeseongkim
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 43bbd277 taeseongkim
    }
116
}
클립보드 이미지 추가 (최대 크기: 500 MB)