Five-query Internet connection status [contains IP]
Collect processing in all directions = "Original", huh, huh. I don't care about it, everyone likes it.
1.powersock control method: This method is the easiest way to use the Localip property of the PowerSock control of the FASTNET page: if (PowerSock1-> localip == "127.0.0.1"): Online ELSE: Offline Features: [1] Judgment Connection state, [2] Get local IP. 2. Use Url.dll's inetisoffline (0) function: win2k: url.dll stores in / system32/; win9x: url.dll stores in / system /; gets the system directory with getSystemDirectory (...). Inetisoffline (0) Return Value: True: Offline; false: Online. Features: Judging the connection status. 3.Winsock Programming: See the Program Features: [1] Judgment the connection status; [2] Get local IP and hostname. 4.Wininet.dll's InternetGetConnectedState (& DWFLAG, 0) function: Note: To use this function, you must add: useElib ("Wininet.Lib") Features: Get more detailed connection description! 5. Rasapi32.dll RaseNumConnections function: To use the "enumeration all activity connection" function, must: #include "ras.h". If the connection is> 0: This machine is currently connected to the Internet; otherwise: This machine is currently not connected to the Internet;
The source code is as follows, through the [BCB5 WIN2K dial-up] (n-head is a menu item): ------------- PowerSock Control Method ---------- ------------------------------- void __fastcall tform1 :: n11click (tobject * sender) {if (PowerSock1-> localip = = "127.0.0.1") ShowMessage ("Not connected:" PowerSock1-> localip); Else ShowMessage ("Connected:" PowerSock1-> localip);} ------------- Url.dll's inetisoffline function method ---------------------------- Hinstance HDLL; typedef BOOL __STDCALL (* fun) (int); definition DLL function pointer fUNFUN isOffLine; void __fastcall TForm1 :: N21Click (TObject * Sender) {char Buffer [MAX_PATH]; GetSystemDirectory (Buffer, MAX_PATH); hDLL = LoadLibrary ((AnsiString (Buffer) "// URL.DLL"). c_str ()); if (hdll == null) {showMessage ("Cannot Load Url! Return ..."); return;} isoffline = (fun) getProcaddress (HDLL, "inetisoffline"); if (isoffline = = NULL) {ShowMessage ("Cannot Load inetisoffline (int), return ..."); return;}}}) ShowMessage; Else ShowMessage ("Not connected"; freeelibrary (HDLL);} ------------ Winsock Method ------------------------------- ------------- ---- void __fastcall TForm1 :: N31Click (TObject * Sender) {WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD (1,1); Start up WinSock WSAStartup (wVersionRequested, & wsaData); --------- ------------------------------ Hostent * P; char * p2; char s [128]; gethostname (s, 128); get the computer name p = gethostbyname (s); p2 = inet_ntoa (* (in_addr *) p-> h_addr)); get the ipaddress ---------------- ------------------------- Ansistring locationip = p2; if (locationip == "127.0.0.1") ShowMessage ("Not connected:" locationIP );
Else ShowMessage ("Connected:" LocationIP); wsacleanup ();} ---------- Wininet.dll's InternetGetConnectedState function method --------------- -void __fastcall tform1 :: n41click (TOBJECT * Sender) {statictext1-> caption = ""; statictext2-> caption = "; statictext3-> caption =" "; staticText4-> caption ="; staticText5-> caption = ""; StaticText6-> Caption = ""; StaticText7-> Caption = ""; DWORD dwFlag; InternetGetConnectedState (& dwFlag, 0); if (dwFlag & INTERNET_CONNECTION_MODEM) StaticText1-> Caption = "Yes"; MODEM else StaticText1- connected> Caption = "No"; if (dwFlag & INTERNET_CONNECTION_LAN) StaticText2-> Caption = "Yes"; LAN connection else StaticText2-> Caption = "No"; if (dwFlag & INTERNET_CONNECTION_PROXY) StaticText3-> Caption = "Yes"; proxy connection Else StaticText3-> CAPTION = "no"; --------- Check if the connection -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------- IF (InternetGetConnectedState (NULL, 0)) staticText4-> CAPTION = "YES"; online else staticText4-> CAP Tion = "no"; if (dwflag & Internet_connection_offline) staticText5-> caption = "yes"; // Offline.