using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net.NetworkInformation; namespace ping { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btn_ping_Click(object sender, EventArgs e) { Ping p = new Ping(); PingReply r; String s = "192.168.1.101"; try { r = p.Send(s); if (r.Status == IPStatus.Success) { MessageBox.Show("ONLINE"); } } catch { MessageBox.Show("OFFLINE"); } } } }
if (r.Status == IPStatus.Success) { MessageBox.Show("ONLINE"); } else { // Check if you end up here }
private static void Main(string[] args) { var p = new Ping(); const string s = "192.168.1.101"; try { var r = p.Send(s); Console.WriteLine(r.Status == IPStatus.Success ? "ONLINE" : "OFFLINE"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)