How to check internet availability in C ++
I wrote one small function to check the internet connection availability.
void cis()
{
if(InternetCheckConnection(NULL,FLAG_ICC_FORCE_CONNECTION,0))
{
cout << "internet alive";
}
}
I am using WinInet.h
for InternetCheckConnection()
. Now the problem is that I am getting the following linker error:
[Linker error] undefined reference to `_imp__InternetCheckConnectionA@12'
I am using DevC ++ for my project. Any ideas on how to fix this linker issue or any other ideas for checking an active internet connection?
Its a linker error. according to the documentation, you need to use a library wininet
. adding -lwininet
to the makefile might work.
For unix
if (system("ping www.google.com -c 2 > /dev/nul") == 0) {
cout << "all good" << endl;
}else{
cout << "bad" << endl;
}
Window
if (system("ping www.google.com -t 2 > nul") == 0) {
cout << "all good" << endl;
}else{
cout << "bad" << endl;
}
It found your title, however you need to set the link to the libraries. Try adding Wininet.lib to your project (try as a file or in linker properties) and make sure the Windows SDK is correctly installed on your system.