1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int ping (char ip[50]);
void main (void)
{
int result;
char ip[50];
strcpy (ip,"129.46.0.2");
result = ping (ip);
printf ("0 pour offline, 1 pour online : %d",result);
getchar();
}
int ping (char ip[50])
{
int result = 0;
char commande[100];
strcpy (commande,"ping ");
strcat (commande,ip);
strcat (commande, " -n 1 > temp");
system(commande);
FILE * temp;
temp = fopen ("temp","r");
char test[50];
while (!feof (temp))
{
fscanf (temp,"%s",test);
printf("%s ",test);
if (strcmp (test,"TTL=128") == 0)
{
result = 1;
}
}
fclose(temp);
return result;
} |
Partager