- #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);
- if (strcmp (test,"TTL=128") == 0)
- {
- result = 1;
- }
- }
- fclose(temp);
- return result;
- }
#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);
if (strcmp (test,"TTL=128") == 0)
{
result = 1;
}
}
fclose(temp);
return result;
}