ping a range of ips

well if i need to ping a range of ips I can use a small script like this#!/bin/bash
for i in { 1…50}
do ping -c2 192.168.0.$i &> /dev/null
if $?=0 ]; then
echo “UP”
else
echo “DOWN”
fi
done

But I need to do this via a C program . How can I achieve the same ?

You can do this with Socket programming in C.
Are you familiar with C programming?
If you are not familiar with Socket programming, you may execute the “ping command” from within your C program and use the result in your program.

You might want to look at the fping utility, which can do multiple pings in parallel and also allows you to specify the range on the command line.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Or nmap:

nmap -sP 192.168.0.1-50

The equivalent for my network scanned my entire class C in three seconds
(three hosts up, 251 down).

Good luck.

ken yap wrote:
> You might want to look at the fping utility, which can do multiple pings
> in parallel and also allows you to specify the range on the command
> line.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJKMly4AAoJEF+XTK08PnB5bbMP/iRTNhUjHlpq/414SV+Pw9cu
mTlxmwXFiJ2ITPlcZsC8Vbt1gHv7lfxKiN+Xd68EiX30e7cQ6NmLScPvUyy1qjPy
FSBm7d3wHvZjZ8gYNLguybNBNukS0/hrBXfvT+pJXTR5rUnXhb4Z2fJw4ffRZM02
VsJbNzEMiGAFefMbhZbOPznHVh6CMxCYzES6huHVUxum5LVeh3m0dlK+F6wLia/8
4S7zl91aYD0dBLV8MGDyY4UTeubB5nRSzcSKp+/U0GZEaGz/bfboitrJ0/nqf6cw
Kh7V+uybEVAJ7WWDcLUiuRfonj7Acpsa2ofyGd8ZrALc/X+qV42pxGuYUp2cj0qp
qucMd8XcH/Sffvf9e/xc9jy6NLO5YD9Cp/ehS/NIH+dvG1u/FHIZ9V/pId0pJvDq
NUwaGRUuG1fttWluESHSlLsN/p5FmQF5UZoN9YRGPNORjve2nk86DaGV4P7W/+mK
xzMxLzVZ5EAtsLTqgJVpnUSZKyLioFzSZi3u6omNlfeALQu0MgTvfPtF9CkfNPXm
FHuPnSuCQCObwi5E5k2ahSlZmDcXEWP+H/ZWM3cLorXQqcgoQfh3FvUcTb34gNmw
896RExNyeVc5Iwn5OerxGJwvwewtG8YBzfmLrE7SkjHxVcAfuUzJu5T27jgBDQ+j
DoZA+T+flUuklyKxwfX2
=VZZF
-----END PGP SIGNATURE-----

you are kidding right??

Kidding?
@tanmaya mentioned in his post that he wants to achieve the same stuff in C. I was responding to that. What is wrong with my response?