if(!InternetGetConnectedState(ref dwFlag, 0))
MessageBox.Show("未连网!");
else
if((dwFlag& INTERNET_CONNECTION_MODEM)!=0)
MessageBox.Show("采用调治解调器上网。");
else
if((dwFlag& INTERNET_CONNECTION_LAN)!=0)
MessageBox.Show("采用网卡上网。");
}
楼上的方案属于非完全性方案,判断发包是否成功.这样永远都会有Bug的.
方法3
usingSystem.Runtime.InteropServices;
privateconst long INTERNET_CONNECTION_MODEM = 1;//Local system uses a modem to connect to the Internet.
privateconst long INTERNET_CONNECTION_LAN = 2; //Local system uses a local area network to connect to the Internet.
privateconst long INTERNET_CONNECTION_PROXY = 4;//Local system uses a proxy server to connect to the Internet.
privateconst long INTERNET_CONNECTION_MODEM_BUSY = 8; //No longer used.
privateconst long INTERNET_CONNECTION_CONFIGURED = 64; //Local system has a valid connection to the Internet, but it might or might not be currently connected.
privateconst long INTERNET_CONNECTION_OFFLINE = 32; // Local system is in offline mode.
privateconst long INTERNET_RAS_INSTALLED = 16; //Local system has RAS installed.
[DllImport("wininet.dll")]
public static extern boolInternetGetConnectedState(out long lpdwFlags, long dwReserved);
protected void Page_Load(object sender, EventArgs e)
{