C#利用判断是否能够连接到Internet
1个回答
展开全部
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = OnLine() ? "已连接" : "未连接";
}
public bool OnLine()
{
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
///注:
/// 选一个好的host ,这里只是举个例子
System.Net.NetworkInformation.PingReply pr = ping.Send("wjshan0808.3vhost.net", 12000);
return pr.Status == System.Net.NetworkInformation.IPStatus.Success;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询