Programmatically check whether my machine has internet access or not

前端 未结 6 1581
面向向阳花
面向向阳花 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:24

    There is actually a very smart way including code snip here.

    It basically using the cmd option: While in CMD hit: route print.

    This will map routing table with an array and will look for 0.0.0.0 as an available internet connection.

    I used it with a while(true){//the code in here } //check for inet connection , else will sleep for 10 mins and check again

提交回复
热议问题