Use Ruby to make a MTU sweep utility (Ping)

Hi

I've had a request to make a utility (I want to use Ruby) that does a
MTU sweep looking for black holes in routes. So I need a library or a
way to run ping in both a OS X, Linux and Windows environment. The
utility will ping an IP and continue to increment the package / payload
size until error if any The MTU will be (max_size + 28). Can I use Ruby
to do this? I found a ping gem and the std. lib has ping as well but
very limited in options. What else is there?

Thanks

···

--
Posted via http://www.ruby-forum.com/.

You could wrap the OS ping variants (Linux and Mac OS X are probably identical, since both use the GNU utils, so you only have to check for Windows) in your own code, and use that.

They all should provide a means to modify packet size (Windows' ping.exe does), so you can achieve your desired result.

···

On 23.01.2010 03:40, Dale Ackerman wrote:

Hi

I've had a request to make a utility (I want to use Ruby) that does a
MTU sweep looking for black holes in routes. So I need a library or a
way to run ping in both a OS X, Linux and Windows environment. The
utility will ping an IP and continue to increment the package / payload
size until error if any The MTU will be (max_size + 28). Can I use Ruby
to do this? I found a ping gem and the std. lib has ping as well but
very limited in options. What else is there?

--
Phillip Gawlowski

You could wrap the OS ping variants (Linux and Mac OS X are probably
identical, since both use the GNU utils, so you only have to check for
Windows) in your own code, and use that.

They all should provide a means to modify packet size (Windows' ping.exe
does), so you can achieve your desired result.

How would I wrap the command line utilities from ruby? I am new to the
ruby.

···

--
Posted via http://www.ruby-forum.com/\.

Simplistic example:

$ ping
usage: ping [-AaDdfnoQqRrv] [-c count] [-i wait] [-l preload] [-M mask | time]
            [-m ttl] [-p pattern] [-S src_addr] [-s packetsize]
            [-t timeout] [-z tos] host
       ping [-AaDdfLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload]
            [-M mask | time] [-m ttl] [-p pattern] [-S src_addr]
            [-s packetsize] [-T ttl] [-t timeout] [-z tos] mcast-group
$ irb
irb(main):001:0> count = 3
=> 3
irb(main):002:0> packetsize = 128
=> 128
irb(main):003:0> host = '127.0.0.1'
=> "127.0.0.1"
irb(main):004:0> `ping -c #{count} -s #{packetsize} #{host}`
=> "PING 127.0.0.1 (127.0.0.1): 128 data bytes\n136 bytes from
127.0.0.1: icmp_seq=0 ttl=64 time=0.171 ms\n136 bytes from 127.0.0.1:
icmp_seq=1 ttl=64 time=0.101 ms\n136 bytes from 127.0.0.1: icmp_seq=2
ttl=64 time=0.103 ms\n\n--- 127.0.0.1 ping statistics ---\n3 packets
transmitted, 3 packets received, 0% packet loss\nround-trip
min/avg/max/stddev = 0.101/0.125/0.171/0.033 ms\n"

···

On Fri, Jan 22, 2010 at 11:03 PM, Dale Ackerman <dale8458@gmail.com> wrote:

You could wrap the OS ping variants (Linux and Mac OS X are probably
identical, since both use the GNU utils, so you only have to check for
Windows) in your own code, and use that.

They all should provide a means to modify packet size (Windows' ping.exe
does), so you can achieve your desired result.

How would I wrap the command line utilities from ruby? I am new to the
ruby.

WOW! Thanks
are those back quotes around the ping command? I guess ruby will just
shell
out and run a command line ?? That's nice... Also how to handle
std-err I am trying to automate the MTU sweep so I want to keep
incrementing the data size and then handle (break) and display the MTU
== max-size + 28 (I think)

···

--
Posted via http://www.ruby-forum.com/.

Yup.

···

On 23.01.2010 05:30, Dale Ackerman wrote:

WOW! Thanks
are those back quotes around the ping command?

--
Phillip Gawlowski

If you want to access stderr, look at the ruby api docs for popen3.
It's a little more complicated than the backticks but it'll get you
access to stderr.

-Jonathan Nielsen

Jonathan Nielsen wrote:

If you want to access stderr, look at the ruby api docs for popen3.
It's a little more complicated than the backticks but it'll get you
access to stderr.

-Jonathan Nielsen

No it looks like the back-ticks will be fine

I have this in a loop

results = `ping -s #{bytes} -c 1 -D #{host}`

the code runs fine localhost and on my godaddy IP hoever it blows up on
another site. But I am not confident I am doing this right so How can I
tell if its my code or a valid black-hole MTU?

Thanks

···

--
Posted via http://www.ruby-forum.com/\.

"blows up" in what way?

···

On Sat, Jan 23, 2010 at 1:39 AM, Dale Ackerman <dale8458@gmail.com> wrote:

I have this in a loop

results = `ping -s #{bytes} -c 1 -D #{host}`

the code runs fine localhost and on my godaddy IP hoever it blows up on
another site. But I am not confident I am doing this right so How can I
tell if its my code or a valid black-hole MTU?

unknown wrote:

"blows up" in what way?

I know that was not very descriptive. I meant to say that the ping its
self failed. I think it is a couple of things none of which is an
error.

1.) The target host blocked pings after a certain count example Site5
does this.

2.) My ping loop is running to fast at which point the host declines and
the ping fails

3.) It's a black hole which is what we are trying to detect.

It looks good now I have it working for Linux, Unix, OS X, BSD, and
Windows...

Thanks you all for your help. Oh I'll share code if anyone is
interested. Not a big deal .. . .

-dale

···

--
Posted via http://www.ruby-forum.com/\.