프로젝트

일반

사용자정보

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

markus / DnsCheckTest / MainWindow.xaml.cs @ master

이력 | 보기 | 이력해설 | 다운로드 (3.16 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 d60f94ee taeseongkim
            //DnsCheckOld();
31 43bbd277 taeseongkim
            DnsCheck();
32
        }
33
34
        private void Button_Click(object sender, RoutedEventArgs e)
35
        {
36 d60f94ee 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 d60f94ee taeseongkim
52 43bbd277 taeseongkim
            foreach (var item in host.Aliases)
53
            {
54
                builder.AppendLine($"  {item}");
55
            }
56
57
            builder.AppendLine("");
58
            builder.AppendLine(" - Address List");
59
60
            foreach (var item in host.AddressList)
61
            {
62
                builder.AppendLine($"  {item.AddressFamily.ToString()} : {item.ToString()}");
63
            }
64
65
            txtHostInfo.Text = builder.ToString();
66
        }
67 f280a4ce taeseongkim
68
        private void DnsCheckOld()
69
        {
70
            var ipaddress = GetDnsAdress();
71
72
            StringBuilder builder = new StringBuilder();
73
74
            var host = Dns.GetHostEntry(ipaddress);
75
76
            builder.AppendLine($"hostName : {host.HostName}");
77
78
            builder.AppendLine("");
79
            builder.AppendLine(" - Aliases");
80
81
            foreach (var item in host.Aliases)
82
            {
83
                builder.AppendLine($"  {item}");
84
            }
85
86
            builder.AppendLine("");
87
            builder.AppendLine(" - Address List");
88
89
            foreach (var item in host.AddressList)
90
            {
91
                builder.AppendLine($"  {item.AddressFamily.ToString()} : {item.ToString()}");
92
            }
93
94
            txtHostInfoOld.Text = builder.ToString();
95
        }
96
97
        public static IPAddress GetDnsAdress()
98
        {
99
            NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
100
101
            foreach (NetworkInterface networkInterface in networkInterfaces)
102
            {
103
                if (networkInterface.OperationalStatus == OperationalStatus.Up)
104
                {
105
                    IPInterfaceProperties ipProperties = networkInterface.GetIPProperties();
106
                    IPAddressCollection dnsAddresses = ipProperties.DnsAddresses;
107
108
                    foreach (IPAddress dnsAdress in dnsAddresses)
109
                    {
110
                        return dnsAdress;
111
                    }
112
                }
113
            }
114
            return null;
115
        }
116 43bbd277 taeseongkim
    }
117
}
클립보드 이미지 추가 (최대 크기: 500 MB)