openSUSE Forums > Programming/Scripting » ping a range of ips

Go Back   openSUSE Forums > Programming/Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read

Programming/Scripting Questions about programming, bash scripts, perl, php, cron jobs, ruby, python, etc.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-Jun-2009, 03:07
tanmaya's Avatar
Puzzled Penguin
 
Join Date: Jun 2008
Location: Mumbai,India
Posts: 42
tanmaya hasn't been rated much yet
Send a message via AIM to tanmaya Send a message via MSN to tanmaya Send a message via Yahoo to tanmaya
Default 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}
doping -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 ?
Reply With Quote
  #2 (permalink)  
Old 12-Jun-2009, 03:40
Parent Penguin
 
Join Date: Sep 2008
Location: Dubai
Posts: 943
syampillai hasn't been rated much yet
Default Re: ping a range of ips

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.
__________________
openSUSE 11.1 (x86_64) with KDE 4.3.0 (Release 158) on MacBook Pro
Reply With Quote
  #3 (permalink)  
Old 12-Jun-2009, 05:50
Flux Capacitor Penguin
 
Join Date: Jun 2008
Location: GMT+10
Posts: 5,109
ken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud ofken_yap has a reputation to be proud of
Default Re: ping a range of ips

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.
Reply With Quote
  #4 (permalink)  
Old 12-Jun-2009, 08:48
Explorer Penguin
 
Join Date: Apr 2009
Posts: 639
ab@novell.com hasn't been rated much yet
Default Re: ping a range of ips

-----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+Xd68EiX30e7cQ6N mLScPvUyy1qjPy
FSBm7d3wHvZjZ8gYNLguybNBNukS0/hrBXfvT+pJXTR5rUnXhb4Z2fJw4ffRZM02
VsJbNzEMiGAFefMbhZbOPznHVh6CMxCYzES6huHVUxum5LVeh3 m0dlK+F6wLia/8
4S7zl91aYD0dBLV8MGDyY4UTeubB5nRSzcSKp+/U0GZEaGz/bfboitrJ0/nqf6cw
Kh7V+uybEVAJ7WWDcLUiuRfonj7Acpsa2ofyGd8ZrALc/X+qV42pxGuYUp2cj0qp
qucMd8XcH/Sffvf9e/xc9jy6NLO5YD9Cp/ehS/NIH+dvG1u/FHIZ9V/pId0pJvDq
NUwaGRUuG1fttWluESHSlLsN/p5FmQF5UZoN9YRGPNORjve2nk86DaGV4P7W/+mK
xzMxLzVZ5EAtsLTqgJVpnUSZKyLioFzSZi3u6omNlfeALQu0Mg TvfPtF9CkfNPXm
FHuPnSuCQCObwi5E5k2ahSlZmDcXEWP+H/ZWM3cLorXQqcgoQfh3FvUcTb34gNmw
896RExNyeVc5Iwn5OerxGJwvwewtG8YBzfmLrE7SkjHxVcAfuU zJu5T27jgBDQ+j
DoZA+T+flUuklyKxwfX2
=VZZF
-----END PGP SIGNATURE-----
Reply With Quote
  #5 (permalink)  
Old 13-Jun-2009, 06:25
Puzzled Penguin
 
Join Date: Sep 2008
Posts: 39
ghostdog74 hasn't been rated much yet
Default Re: ping a range of ips

Quote:
Originally Posted by syampillai View Post
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 are kidding right??
Reply With Quote
  #6 (permalink)  
Old 13-Jun-2009, 07:33
Parent Penguin
 
Join Date: Sep 2008
Location: Dubai
Posts: 943
syampillai hasn't been rated much yet
Default Re: ping a range of ips

Quote:
Originally Posted by ghostdog74 View Post
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?
__________________
openSUSE 11.1 (x86_64) with KDE 4.3.0 (Release 158) on MacBook Pro
Reply With Quote
Reply

Bookmarks


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2