Programmatically check whether my machine has internet access or not

前端 未结 6 1572
面向向阳花
面向向阳花 2020-12-17 17:23

How can I programmatically check whether my machine has internet access or not using C/C++, is it just a matter of pinging an IP? How does NIC do it ? I mean something like

6条回答
  •  隐瞒了意图╮
    2020-12-17 18:01

    In addition to the InternetCheckConnection() function, The Win32 API has a function ( InternetGetConnectedState() ) which returns a true/false for (the availability of) some form of internet connectivity:

    https://msdn.microsoft.com/en-us/library/windows/desktop/aa384702(v=vs.85).aspx

    It also tells you what type of connection to the internet you have(LAN, modem, Proxy etc) - which can often be very handy to know.

提交回复
热议问题