C#檢查網(wǎng)絡(luò)是否連通
C#.Net檢測網(wǎng)絡(luò)在線狀態(tài)
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Runtime.InteropServices; namespace Jsons.cn { public partial class Connected : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //True 為連通 False 為斷開 bool Urlstate = IsConnected(); Response.Write(Urlstate); } [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue); /// <summary> /// C#檢查網(wǎng)絡(luò)是否連通 /// </summary> /// <returns></returns> private bool IsConnected() { int I = 0; bool state = InternetGetConnectedState(out I, 0); return state; } } }