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?

+3


source to share


3 answers


Its a linker error. according to the documentation, you need to use a library wininet

. adding -lwininet

to the makefile might work.



+5


source


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

      

+1


source


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.

0


source







All Articles