判断是否连上internet,该怎么处理
判断是否连上internet
我在网上看到很多方法
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
private void button1_Click(object sender, EventArgs e)
{
int I = 0;
bool check = InternetGetConnectedState(out I, 0);
if (check == true)
{
MessageBox.Show("连上internet");
}
else if (check == false)
{
MessageBox.Show("没连上");
}
}
我发觉这个方法只能判断机子有无连上局域网。。
那判断有无连上internet应该怎样做呢??
------解决方案--------------------
沙发,学习~
------解决方案--------------------
沙发,哎呀板凳,呵呵呵
------解决方案--------------------
ping的通 www.baidu.com
*****************************************************************************
欢迎使用****论坛专用阅读器 : **** Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
------解决方案--------------------
我在网上看到很多方法
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
private void button1_Click(object sender, EventArgs e)
{
int I = 0;
bool check = InternetGetConnectedState(out I, 0);
if (check == true)
{
MessageBox.Show("连上internet");
}
else if (check == false)
{
MessageBox.Show("没连上");
}
}
我发觉这个方法只能判断机子有无连上局域网。。
那判断有无连上internet应该怎样做呢??
------解决方案--------------------
沙发,学习~
------解决方案--------------------
沙发,哎呀板凳,呵呵呵
------解决方案--------------------
ping的通 www.baidu.com
*****************************************************************************
欢迎使用****论坛专用阅读器 : **** Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
------解决方案--------------------
- C# code
//检测网络连接是否连接到Internet [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue); public bool IsConnected() { int connectionDescription = 0; //判断是否连接到外网上的函数,并返回布尔值 return InternetGetConnectedState(out connectionDescription, 0); }
------解决方案--------------------
这样不能判断连接到外网吗?
------解决方案--------------------
BOOL InternetGetConnectedStateEx(
__out LPDWORD lpdwFlags,
__out LPTSTR lpszConnectionName,
__in DWORD dwNameLen,
__in DWORD dwReserved
);
------解决方案--------------------
- C# code
private void button1_Click(object sender, EventArgs e) { bool flag = IsConnected(); MessageBox.Show(flag.ToString()); } [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue); public bool IsConnected() { int connectionDescription = 0; //判断是否连接到外网上的函数,并返回布尔值 return InternetGetConnectedState(out connectionDescription, 0); }
------解决方案--------------------
我试了可以啊,把直接断网后就是false了
InternetGetConnectedState这个就是判断是否连接Internet的API函数,方法肯定没错的
------解决方案--------------------
学习
------解决方案--------------------
更详细的方法,搂主可以看看下面网页:
http://www.zdwork.cn/content/20084/68.htm
------解决方案--------------------
学习了哈`````````
------解决方案--------------------
学习了
------解决方案--------------------
最绝的办法不如搂主直接Ping 百度或google之类的网站
.net下使用System.Net.NetworkInformation.Ping的Send方法
ping.Send("www.google.cn",......)
------解决方案--------------------