anoyinginternetcheck.c/anoyinginternetcheck.c

45 lines
1.2 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
#define YELLOW "\x1b[33m"
#define BLUE "\x1b[34m"
#define MAGENTA "\x1b[35m"
#define CYAN "\x1b[36m"
#define RESET "\x1b[0m"
int main(int argc, char **argv) {
if (argc < 3) {
printf("Usage: %s [ip1] [ip2]\n", argv[0]);
exit(EXIT_FAILURE);
}
int i=0;
static char command[128] = "ping -c 1 ";
static char command2[128] = "ping -c 1 ";
setbuf(stdout, NULL);
strcat(command, argv[1]);
strcat(command2, argv[2]);
strcat(command, "> /dev/null");
strcat(command2, "> /dev/null");
while (1) {
int res = system(command);
sleep(1);
if (res != 0) {
printf(RED "No connection to %s, trying other host\n" RESET, argv[1]);
res = system(command2);
} if (res != 0) {
printf(RED "\nNo connection to %s either, beeping your shit\n" RESET, argv[2]);
while (i<20) { system("beep -f 2500 -l 200 -n -f 4000 -l 200"); i++; } i=0;
printf(MAGENTA "Checking again in 15 seconds\n" RESET);
sleep(15);
} else {
printf(GREEN "You have internet :), checking again in 1 minute\n" RESET);
sleep(60);
}
}
exit(EXIT_SUCCESS);
}