Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Runtime. InteropServices;
Namespace MeshworkLinkMode
{
Class Program
{
Static void Main (string [] args)
{
Console. WriteLine ("using InternetGetConnectedState to determine the network connection mode ");
Console. WriteLine (Fun_InternetGetConnectedState ());
Console. WriteLine ("using IsNetworkAlive to determine the network connection mode ");
Console. WriteLine (Fun_IsNetworkAlive ());
Console. ReadLine ();
}
[DllImport ("wininet. dll")]
Private extern static bool InternetGetConnectedState (out int connectionDescription, int reservedValue );
[DllImport ("sensapi. dll")]
Private extern static bool IsNetworkAlive (out int connectionDescription );
Static string Fun_InternetGetConnectedState ()
{
Int INTERNET_CONNECTION_MODEM = 1;
Int INTERNET_CONNECTION_LAN = 2;
Int INTERNET_CONNECTION_PROXY = 4;
Int INTERNET_CONNECTION_MODEM_BUSY = 8;
String outPut = null;
Int flags; // method of surfing the internet
Bool m_bOnline = true; // whether it is online
M_bOnline = InternetGetConnectedState (out flags, 0 );
If (m_bOnline) // online
{
If (flags & INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM)
{
OutPut = "online: dial-up Internet ";
}
If (flags & INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN)
{
OutPut = "online: via LAN ";
}
If (flags & INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY)
{
OutPut = "online: proxy ";
}
If (flags & INTERNET_CONNECTION_MODEM_BUSY) = INTERNET_CONNECTION_MODEM_BUSY)
{
OutPut = "MODEM is occupied by other non-INTERNET connections ";
}
}
Else
{
OutPut = "not online ";
}
Return outPut;
}
Static string Fun_IsNetworkAlive ()
{
Int NETWORK_ALIVE_LAN = 0;
Int NETWORK_ALIVE_WAN = 2;
Int NETWORK_ALIVE_AOL = 4;
String outPut = null;
Int flags; // method of surfing the internet
Bool m_bOnline = true; // whether it is online
M_bOnline = IsNetworkAlive (out flags );
If (m_bOnline) // online
{
If (flags & NETWORK_ALIVE_LAN) = NETWORK_ALIVE_LAN)
{
OutPut = "online: NETWORK_ALIVE_LAN ";
}
If (flags & NETWORK_ALIVE_WAN) = NETWORK_ALIVE_WAN)
{
OutPut = "online: NETWORK_ALIVE_WAN ";
}
If (flags & NETWORK_ALIVE_AOL) = NETWORK_ALIVE_AOL)
{
OutPut = "online: NETWORK_ALIVE_AOL ";
& Nb