用的api为InternetGetConnectedState,位于Wininet.dll中,MSDN:http://msdn.microsoft.com/en-us/library/windows/desktop/aa384702(v=vs.85).aspx

经测试,发现该api不能真正检测电脑inernet状态,只能获取电脑是否正确连接modem或lan,要想准确检测电脑是否联网,还需要请求下远程服务器.

::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;
}
}