我试图找到如何获取我的 ping 并找到以下代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;
using System.IO;
using System.Configuration;
using System.Web;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Ping ping = new Ping();
PingReply pingreply = ping.Send("www.google.com");
StreamWriter sw = new StreamWriter(@"C:\ping.txt");
StringBuilder sb = new StringBuilder();
sb.Append("Address: " + pingreply.Address + "\r\n");
sb.Append("Roundtrip Time: " + pingreply.RoundtripTime + "\r\n");
sb.Append("TTL (Time To Live): " + pingreply.Options.Ttl + "\r\n");
sb.Append("Buffer Size: " + pingreply.Buffer.Length.ToString() + "\r\n");
sb.Append("Time : " + DateTime.Now + "\r\n");
sw.Write(sb.ToString());
sw.Close();
}
catch (Exception err)
{
}
}
}
}
我试图做这样的事情:
label1.Text = pingreply.Buffer.Length.ToString();
但它无法获得 ping,我无法弄清楚如何在标签上获得它,有谁知道如何做到这一点?