Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Net;
- using System.Net.NetworkInformation;
- namespace WpfApplication1
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public void DoThePing() {
- try
- {
- Ping pingSender = new Ping();
- PingReply MainServer = pingSender.Send("www.pattersoncode.ca");
- PingReply BackupServer = pingSender.Send("82.145.60.186");
- PingReply CDN = pingSender.Send("d11ghhslktyes5.cloudfront.net");
- if (MainServer.Status == IPStatus.Success)
- {
- mainlabel.Content = MainServer.RoundtripTime + " ms";
- mainlabel.Foreground = Brushes.DarkGreen;
- }
- else
- {
- mainlabel.Content = "Failure";
- mainlabel.Foreground = Brushes.Red;
- }
- if (CDN.Status == IPStatus.Success)
- {
- cdnlabel.Content = CDN.RoundtripTime + " ms";
- cdnlabel.Foreground = Brushes.DarkGreen;
- }
- else
- {
- cdnlabel.Content = "Failure";
- cdnlabel.Foreground = Brushes.Red;
- }
- if (BackupServer.Status == IPStatus.Success)
- {
- backuplabel.Content = BackupServer.RoundtripTime + " ms";
- backuplabel.Foreground = Brushes.DarkGreen;
- }
- else
- {
- backuplabel.Content = "Failure";
- backuplabel.Foreground = Brushes.Red;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "Exception");
- }
- }
- public MainWindow()
- {
- InitializeComponent();
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- DoThePing();
- }
- private void Grid_Loaded(object sender, RoutedEventArgs e)
- {
- DoThePing();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement