c# 网络是否连接
c# 网络是否连接
方案一:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Runtime.InteropServices;//必须引用这个命名空间 namespace NetWorkConn_Demo
{
class Program
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue); static void Main(string[] args)
{
int flag = ;
var isConn = InternetGetConnectedState(out flag, );
if (isConn)
{
Console.WriteLine("网络已连接!");
}
else
{
Console.WriteLine("网络已断开!");
}
Console.ReadKey();
}
}
}
方案二: 【不好】
Ping p = new Ping();
PingReply reply = p.Send("192.168.0.0", 100);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine("网络已连接!");
}
else
{
Console.WriteLine("网络已断开!");
}
c# 网络是否连接的更多相关文章
- monkey工具使用中遇到的问题之一:手机模拟器中的部分应用出现网络无法连接
问题描述: 手机模拟器中的部分应用出现网络无法连接,但是比如:浏览器即可以正常访问网页 解决方法如下: 1.以管理员身份进入到cmd中,以WIN10为例 ,在电脑左下角点击鼠标右键就可以看到 注意: ...
- Reachability(判断网络是否连接)
类似于一个网络状况的探针. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabili ...
- 判断网络是否连接 和 判断GPS是否连接
//判断网络是否连接 public static Boolean isNetworkEnabled(Context context){ int status=-1 //设置默认连接的状态为-1 Co ...
- android 检测网络是否连接,或者GPS是否可用
很多android程序在打开时,检测网络是否连接,或者GPS是否可用: 1.网络是否连接(包括Wifi和移动网络) // 是否有可用网络 private boolean isNetworkConnec ...
- Android判断网络是否连接
<!-- 配置文件判断网络是否连接 --> <uses-permission android:name="android.permission.ACCESS_NETWORK ...
- android 判断网络是否连接
package com.liucanwen.baidulocation.util; import android.app.Activity; import android.content.Contex ...
- Reachability判断网络是否连接
类似于一个网络状况的探针. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabili ...
- javascript 网络是否连接的几种方案
js 网络是否连接的几种方案 1.通过html5的新属性: window.onload = function () { var isOnLine = navigator.on ...
- c# 判断网络是连接到互联网
方法1:InternetGetConnectedState [System.Runtime.InteropServices.DllImport("wininet") ...
随机推荐
- 如何不通过系统升级来安装window10正式版?(特别针对Xp用户)
今天是个特殊的日子7/29,相信大家都等了很久了吧,win10正式版终于上线,一些不懂电脑的人只会通过360和腾讯管家等来升级到win10(XP用户除外),而对于大多数像我这样对系统比较热衷的人,我相 ...
- elasticsearch-查询的基本语法
elasticsearch的查询有两部分组成:query and filter. 两者的主要区别在于:filter是不计算相关性的,同时可以cache.因此,filter速度要快于query. 先记录 ...
- cygwin and its host machine
Senario 本来我是想要修改下 machine name 在Ubuntu中的步骤是这样的 1 sudo hostname newMechineName 2 sudo vi /etc/hostnam ...
- 老陈 ASP.NET封装
第一个页面 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data ...
- sql records
DROP TABLE IF EXISTS student; CREATE TABLE student ( id INT NOT NULL AUTO_INCREMENT, student_name ) ...
- Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8 (转)
Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8http://www.crifan.com/android_emulator_ ...
- Kali Linux 命令集
系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...
- Ruby Profiler 详解之 ruby-prof(I)
项目地址: ruby-prof 在上一篇 Ruby 中的 Profiling 工具中,我们列举了几种最常用的 Profiler,不过只是简单介绍,这一次详细介绍一下 ruby-prof 的使用方法. ...
- SQL技术内幕-8 使用WITH AS提高性能简化嵌套SQL
--本文来源:http://www.cnblogs.com/fygh/archive/2011/08/31/2160266.html 一.WITH AS的含义 WITH AS短语,也叫做子查询部分(s ...
- 14个Xcode中常用的快捷键操作
在Xcode 6中有许多快捷键的设定可以使得你的编程工作更为高效,对于在代码文件中快速导航.定位Bug以及新增应用特性都是极有效的. 当然,你戳进这篇文章的目的也在于想要快速的对代码文件进行操作,或者 ...