2

I'm needing to ping about 2500 servers at one time, in intervals of about 15-30 minutes. This is to show semi-real time server status information. This could potentially scale to tens of thousands of sites eventually, so I need to keep that in mind while thinking about this.

I'm using an Ubuntu 10.10 VPS (Bash) and using Ruby.

Is there any way to go about doing this?

Edit: I should also note that I only care if the server is online. So first packet received should suffice.

Chuck Callebs
  • 16,293
  • 8
  • 56
  • 71

1 Answers1

3

I'd consider shelling to nmap or its like. It's well tuned to that purpose, being quite fast, and it contains enough different ways to ping to satisfy any need. Here's using nmap to discover all hosts on a segment of my network:

wayne@treebeard:~$ nmap -sP 10.0.0.0/24
Starting Nmap 5.00 ( http://nmap.org ) at 2010-12-08 09:16 MST
Host gw (10.0.0.1) is up (0.00036s latency).
Host 10.0.0.2 is up (0.0071s latency).
Host isengard.internal.databill.com (10.0.0.3) is up (0.00062s latency).
...
Host arod.internal.databill.com (10.0.0.189) is up (0.0046s latency).
Host 10.0.0.254 is up (0.00042s latency).
Nmap done: 256 IP addresses (43 hosts up) scanned in 3.00 seconds

Here we've scanned for all hosts from 10.0.0.0 through 10.0.0.255.

-sP is a "ping scan", a pretty generic host discovery mechanism that can be run as an ordinary user. There are other types of scan that nmap does, many of them needing root privileges.

In Ruby, you'll use backtick or IO.popen to run nmap and capture its results:

output = `nmap -sP 10.0.0.0/24
output.each_line.find_all do |lines|
  line =~ /^Host/
end.each do |line|
  # Whatever you want to do for each host
end

If you supply the -oX switch, nmap will output xml, which may be easier to parse (thanks, tadman).

Wayne Conrad
  • 103,207
  • 26
  • 155
  • 191