用API可以解决 [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue); static int flag; static string State = InternetGetConnectedState(out flag, 0).ToString(); static void Main(string[] args) { Console.WriteLine(State); Console.Read(); }刚试了一下 ok 记得要 using System.Runtime.InteropServices;
[DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int ConnectionDescription, int ReservedValue); public static bool OnlineState() { int i = 0; return InternetGetConnectedState(out i, 0); }
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
static int flag;
static string State = InternetGetConnectedState(out flag, 0).ToString();
static void Main(string[] args)
{
Console.WriteLine(State);
Console.Read();
}刚试了一下 ok
记得要 using System.Runtime.InteropServices;
private extern static bool InternetGetConnectedState(out int ConnectionDescription, int ReservedValue); public static bool OnlineState()
{
int i = 0;
return InternetGetConnectedState(out i, 0);
}
1.RasEnumConnections 枚举所有拨号连接
2.RasHangUp 对每个枚举到的连接执行挂起操作(断开连接)
用webrequest get 看看服务器返回值就可以了
{
string pingrst; Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); p.StandardInput.WriteLine("ping -n 1 -w "+timeOut.ToString()+" " + URL); p.StandardInput.WriteLine("exit"); string strRst = p.StandardOutput.ReadToEnd(); if(strRst.IndexOf("(0% loss)")!=-1)
{
return true;
}
else
{
return false;
} }