After testing, it is found that this api cannot really detect the inernet status of the computer. It can only obtain whether the computer is correctly connected to the modem or lan. To accurately detect whether the computer is connected to the Internet, you also need to request a remote server.
| The Code is as follows: |
Copy code |
: Wininet: = .. raw. loadDll ("Wininet. dll ") : InternetGetConnectedState = Wininet. api ("InternetGetConnectedState", "bool (int & flag, int Reserved )")
IsOnline = function (){ Return InternetGetConnectedState (0, 0 ); }
Io. open () Io. print (isOnline ()) Using System. Runtime. InteropServices; Class inet { [DllImport ("wininet. dll")] Extern static bool InternetGetConnectedState (out int connectionDescription, int
ReservedValue ); Public bool isOnline () { Int flag = 0; Bool state = InternetGetConnectedState (out flag, 0 ); Return state; } } |