// Testnetconnection. CPP: defines the entry point for the console application. <br/> // test. CPP: defines the entry point for the console application. <br/> // <br/> # include "stdafx. H "<br/> # include <windows. h> <br/> # include <iostream> <br/> using namespace STD; <br/> # include <wininet. h> <br/> # pragma comment (Lib, "wininet. lib ") <br/> # include <sensapi. h> <br/> # pragma comment (Lib, "sensapi. l IB ") <br/>/* <br/> // local network connection type (successful) <br/> # define net_type_ras_dial_up_connect_net 0x01 // Internet access type: use Ras dial-up connection to access the Internet 0x01 <br/> # define net_type_lan_connect_net 0x02 // type of access to the Internet: use a network adapter to access the Internet through a LAN 0x02 <br/> # define net_type_proxy_connect_net 0x04 // Internet type: use the proxy server to access the Internet 0x04 <br/> # define net_type_ras_install 0x10 // ras to install 0x10 <br/> */<br/> void fun_internetgetconnectedstate () <br/>{< br/> DWORD flags; // method of surfing the Internet <br/> bool m_bonline = true; // Online or not <br/> m_bonline = internetgetconnectedstate (& flags, 0); <br/> If (m_bonline) // online <br/>{< br/> If (flags & internet_connection_modem) == internet_connection_modem) <br/>{< br/> cout <"online: dial-up Internet access/N "; <br/>}< br/> If (flags & internet_connection_lan) = internet_connection_lan) <br/>{ <br/> cout <"online: via LAN/N"; <br/>}< br/> If (flags & internet_connection_proxy) = internet_connection_proxy) <br/>{< br/> cout <"Online: proxy/N"; <br/>}< br/> If (flags & internet_connection_modem_busy) = internet_connection_modem_busy) <br/>{< br/> cout <"modem is occupied by other non-Internet connections/N "; <br/>}< br/> else <br/> cout <"not online/N "; <br/>}< br/> void fun_isnetworkalive () <br/>{< br/> DWORD flags; // method of surfing the Internet <br/> bool m_bonline = true; // online or not <br/> m_bonline = isnetworkalive (& flags); <br/> If (m_bonline) // online <br/>{< br/> If (flags & network_alive_lan) = Network_alive_lan) <br/>{< br/> cout <"online: network_alive_lan/N"; <br/>}< br/> If (flags & network_alive_wan) = network_alive_wan) <br/>{< br/> cout <"online: network_alive_wan/N"; <br/>}< br/> If (flags & network_alive_aol) = network_alive_aol) <br/>{< br/> cout <"online: network_alive_aol/N "; <br/>}< br/> else <br/> cout <"not online/N "; <br/>}< br/> int _ tmain (INT argc, _ tchar * argv []) <br/>{< br/> int nretcode = 0; <br/> int I = 0; <br/> while (true) <br/>{< br/> cout <"select the Test method: /n "<br/> <" 1. internetgetconnectedstate/N "<br/> <" 2. isnetworkalive "<br/> <Endl; <br/> CIN> I; <br/> switch (I) <br/>{< br/> case 1: <br/> fun_internetgetconnectedstate (); <br/> break; <br/> case 2: <br/> fun_isnetworkalive (); <br/> break; <br/> default: <br/> cout <"error! /N "; <br/>}< br/> cout <Endl; <br/>}< br/> return nretcode; <br/>}< br/>