判断是否连网

网友投稿 578 2022-10-17

判断是否连网

判断是否连网

1、​​using​​​ ​​System;​​

using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.NetworkInformation; namespace 判断是否联网 { class Program { static void Main(string[] args) { Ping p = new Ping(); PingReply pr; pr = p.Send("119.75.218.45");//百度的IP if (pr.Status != IPStatus.Success)//如果连接不成功 { Console.WriteLine("未联网"); } else { Console.WriteLine("已联网"); } Console.Read(); } } }

2、

WebRequest myrequest = WebRequest.Create(" WebResponse myres = null; try { myres = myrequest.GetResponse(); myres.Close(); MessageBox.Show("连上了"); } catch (Exception) { MessageBox.Show("连不上了"); }

3、

public partial class Form1 : Form{ //判断网络连接 [DllImport("wininet")] private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue); ///

/// 检测本机的网络连接 /// private void button1_Click(object sender, EventArgs e) { //判断是否联网 int i = 0; if (InternetGetConnectedState(out i, 0)) { //联网 MessageBox.Show("Thylx提醒您:你的计算机已连接到网络上!"); } else { //断网 MessageBox.Show("Thylx提醒您:本地连接已断开!"); } }}

龙腾一族至尊龙骑

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:eBayUI- eBay 的 Web UI 框架
下一篇:IDEA文件夹邮件提示Open Folder as IntelliJ IDEA Community Edition Project
相关文章

 发表评论

暂时没有评论,来抢沙发吧~