728x90
반응형
WPF & C# - 핑 테스트 Ping Test ( PingOptions Class ) |
MainWindow.xaml
1 2 3 4 | <StackPanel> <Button x:Name="btn" Height="35" Click="btn_Click" Content="Ping Test"></Button> <Label x:Name="lbl"></Label> </StackPanel> | cs |
MainWindow.xaml.cs
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 | private void btn_Click(object sender, RoutedEventArgs e) { Ping pingSender = new Ping(); PingOptions options = new PingOptions(); // Use the default Ttl value which is 128, // but change the fragmentation behavior. options.DontFragment = true; // Create a buffer of 32 bytes of data to be transmitted. string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 120; PingReply reply = pingSender.Send("google.com", timeout, buffer, options); if (reply.Status == IPStatus.Success) { for(int i = 0; i < 4; i++) { string str = string.Empty; str += "Address: " + reply.Address.ToString() + "\n"; // 주소 str += "RoundTrip time: " + reply.RoundtripTime + "\n"; // 응답시간 str += "Time to live: " + reply.Options.Ttl + "\n"; // TTL : 데이터의 유효 기간 str += "Don't fragment: " + reply.Options.DontFragment + "\n"; // 손실데이터 유무 str += "Buffer size: " + reply.Buffer.Length + "\n\n"; // 버퍼사이즈 lbl.Content += str; } } } | cs |
Ping
728x90
반응형