Jump to content



Recommended Posts

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
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 
case 2: //alternative exit option
return 0; //ends
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;

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...