Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Ping a range of IP addresses (See related posts)

(1..254).each {|i| puts ": found 192.168.1.#{i}" if  `ping 192.168.1.#{i} -c 1 -w 1`.match(/ttl/) }

Comments on this post

alxx posts on Mar 11, 2008 at 05:50
What's wrong with simply pinging the broadcast? ping 192.168.1.255
jrobertson posts on Mar 11, 2008 at 06:44
I wasn't aware of pinging the broadcast, that would have saved me a lot of time troubleshooting network problems for friends and family in the past. Thank you for that information.
hashcode posts on Mar 11, 2008 at 12:52
Here, another solution using the pure-ruby.
require 'ping' #from core classes
ip_prefix='192.168.1.'
(1..254).each{|i| puts "Found #{ip_prefix}" if Ping.pingecho(ip_prefix+i.to_s,10) }

You need to create an account or log in to post comments to this site.


Click here to browse all 4834 code snippets

Related Posts