Pinging with C/C++ - Raspberry Pi Forums


howdy,

here want accomplish: want ping ip, every 5 seconds, , print out message telling me if ip or down. appreciate ideas of how can better, i'm sure not best implementation.

code thusfar:
(the results of code "server down" message". when try , print results of ping variable "file2", end weird string of nonsense characters. idea display string hex or binary, , bitwise , string number leaves either 1 (true, ping success) or 0 (false, ping fail) can test if statement.)

code: select all

#include <stdio.h> #include <iostream> #include <stdlib.h> #include <unistd.h>  int main(void){ std::string file2; char file2[256]; file* file;  file = popen("ping -c 2 -i 5 10.28.33.120", "r");  sleep(5); fprintf(file,file2); printf("%s \n", file2);  	if (file == 0){ 		printf("network good\n"); 			} 	if (file != 0){ 		printf("network down\n"); 	              } } 
thanks!

wouldn't lot easier shell script rather c program?


raspberrypi



Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support