xeemo Posted November 22, 2009 Share Posted November 22, 2009 So the internet went down the other day and I got really bored. I made a program to beep at me when the internet connection came back on. Thought I would post it here in case someone could use it. I'm aware that the string doesn't need to be that big, I just never bothered to change it(it works all the same though). /*coded by xeemo 2009 because the internet connection went out and it was boring.*/ #include <stdio.h> //standard input and output #include <string.h> //needed for handling strings #include <unistd.h> //needed to read pipes from files int length; // variable for string length int main(){ FILE * ping; //activates the ping file char pingo[80]; //string for ping reply int lastchar; //variable to send the characters to the string from the pipe ping = popen("ping google.com", "r"); //command inserted for file in read mode through pipe lastchar = fread(pingo, 1, 80, ping); //characters 1 through 80 are read from the pipe pingo[lastchar] = '\0'; //pingo is a null terminated string through lastchar length = strlen(pingo); //length of string piped in if(length == 0){ //if no string was piped go to this select screen int select; //option variable printf("\ainternet is down. enter 1 to have system alert you when you have internet. enter 2 to exit.\n"); //beep and display message scanf("%i",&select); //get input from user switch(select){ case 1: loop: //loop this until you get a reply if(length == 0){ FILE * ping; ping = popen("ping google.com", "r"); lastchar = fread(pingo, 1, 80, ping); pingo[lastchar] = '\0'; pclose(ping); //close the ping file length = strlen(pingo); usleep(9000000); //spaces connections out so it doesn't crash if(length == 0){ //checks for connection again goto loop; //loops above if you're still offline } } if(length != 0){ printf("\ayour internet connection has returned\n");//beeps and alerts user when connected } break; case 2: //alternative exit option return 0; //ends default: printf("\aerror"); //what are you stupid? enter 1 or 2 like the menu says. } } if(length != 0){ //internet connection is up printf("\ayour internet is working\n"); } pclose(ping); //close ping file return 0; } Quote Link to comment Share on other sites More sharing options...
operat0r_001 Posted December 9, 2009 Share Posted December 9, 2009 you can do this with ping yahoo.com and error levels ( exit codes for *nix users ) http://www.robvanderwoude.com/errorlevel.php :loop Timeout.exe 30 ping yahoo.com if errorlevel 1 goto restartvnc Timeout.exe 30 goto loop something like that Quote Link to comment Share on other sites More sharing options...
Kerberos Posted December 9, 2009 Share Posted December 9, 2009 Cool :P Never hurts to flex the programming muscle every once in a while. A few days ago I threw together some Javascript to crack terminal passwords in Fallout 3 because I was tired of doing it pen-and-paper every time :D. Practice keeps it fresh in your mind ;) Quote Link to comment Share on other sites More sharing options...
ParMan Posted December 9, 2009 Share Posted December 9, 2009 nice little program you made i like how you comment on everything. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.