ARP Ping and ICMP in Ruby?

R

Ruby Rubyruby

What would I have to do in order to be able to send an ARP Ping or a
regular ICMP_ECHO_REQUEST in Ruby? Is it possible?
 
K

Konrad Meyer

--nextPart2506670.Lt7uc5MZgO
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

=20
require 'ping'
=20
Ping.pingecho('example.com')

Unfortunately, this isn't a 'ICMP_ECHO_REQUEST', it's an attempt to connect
to the remote machine on the 'echo' port. If the connection is refused or
allowed, pingecho() returns true. If it times out, or otherwise errors,
it returns false. Either way, it's not ICMP if you *need* ICMP.
or
=20
system('ping -c1 www.example.com')

Shelling out to a ping command is probably a bad idea for portability
reasons.

If a TCP connection test works for you then go with the stdlib Ping library.
If it doesn't, you might look into RubyInline or writing a simple C
extension for basic ICMP requests.

Cheers!
=2D-=20
Konrad Meyer <[email protected]> http://konrad.sobertillnoon.com/

--nextPart2506670.Lt7uc5MZgO
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBGvO6UCHB0oCiR2cwRApTYAJ9vgCas3q2oE3hLiI0Efk8wEeCmHwCgua9h
MVkR6DS9m47oB53mCkSqrUg=
=ffS7
-----END PGP SIGNATURE-----

--nextPart2506670.Lt7uc5MZgO--
 
D

Daniel Berger

What would I have to do in order to be able to send an ARP Ping or a
regular ICMP_ECHO_REQUEST in Ruby? Is it possible?

require 'net/ping'
include Net

icmp = Ping::ICMP.new('foo.com')

if icmp.ping?
# Successful
else
# Failed
end

gem install net-ping

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top