# Net::PingExternal gives an errror

**URL:** <https://www.ruby-forum.com/t/net-pingexternal-gives-an-errror/195084>\
**Category:** Ruby\
**Created:** [September 16, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/net-pingexternal-gives-an-errror/195084 "2010-09-16T16:22:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![webwizart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@webwizart](https://www.ruby-forum.com/u/webwizart)\
**Post date:** [September 16, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/net-pingexternal-gives-an-errror/195084/1 "2010-09-16T16:22:38Z")

</div>

Hello there,

I’m having a problem with a tutorial to ping whatever.  
I have snowleopard and both ruby’s both give the same error:

uninitialized constant Net::PingExternal (NameError)

here is the code i’m using:

require ‘rubygems’  
require ‘net/ping’  
if Net::PingExternal.new(‘localhost’).ping  
puts ‘Localhost OK’  
else  
puts ‘Localhost NO respons’  
end

i dont know what to do.  
I cleaned en update macports  
updated rubygems and rubygems1.9  
reinstalled ruby 1.8.7 and ruby1.9

Some help woud be nice thx

---

<div class="post-metadata">

**Author:** ![webwizart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@webwizart](https://www.ruby-forum.com/u/webwizart)\
**Post date:** [September 16, 2010, 5:11pm UTC](https://www.ruby-forum.com/t/net-pingexternal-gives-an-errror/195084/2 "2010-09-16T17:11:56Z")

</div>

On Sep 16, 2010, at 4:22 PM, Younes B. wrote:

> require ‘net/ping’  
> if Net::PingExternal.new(‘localhost’).ping  
> puts ‘Localhost OK’  
> else  
> puts ‘Localhost NO respons’  
> end

# gem i net-ping

require ‘rubygems’  
require ‘net/ping’  
o = Net::Ping::TCP.new ‘[www.ccc.de](http://www.ccc.de)’, 80  
o.ping? # =\> true

All the best, Sandor  
Szücs

---

<div class="post-metadata">

**Author:** ![webwizart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@webwizart](https://www.ruby-forum.com/u/webwizart)\
**Post date:** [September 16, 2010, 6:37pm UTC](https://www.ruby-forum.com/t/net-pingexternal-gives-an-errror/195084/3 "2010-09-16T18:37:24Z")

</div>

On Sep 16, 8:22 am, Younes B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello there,
> 
> I’m having a problem with a tutorial to ping whatever.  
> I have snowleopard and both ruby’s both give the same error:
> 
> uninitialized constant Net::PingExternal (NameError)

Try Net::Ping::External

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![webwizart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@webwizart](https://www.ruby-forum.com/u/webwizart)\
**Post date:** [September 17, 2010, 12:15am UTC](https://www.ruby-forum.com/t/net-pingexternal-gives-an-errror/195084/4 "2010-09-17T00:15:42Z")

</div>

thanks it works but its not correct i try them both:

if Net::Ping::TCP.new(‘loocaalhost’)  
puts ‘OK’  
else  
puts ‘NO respons’  
end

if Net::Ping::External.new(‘loccalhost’)  
puts ‘OK’  
else  
puts ‘NO respons’  
end

this is the output:  
OK  
OK  
webwizartbe-iMac:balbaert younesbaghor$

2 times ok even when the localhost is spelled wrong.

someone know what the difference is between  
Net::Ping::TCP.new(‘localhost’)  
Net::Ping::External.new(‘localhost’)

thanks allot

---

<div class="post-metadata">

**Author:** ![webwizart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@webwizart](https://www.ruby-forum.com/u/webwizart)\
**Post date:** [September 17, 2010, 12:38am UTC](https://www.ruby-forum.com/t/net-pingexternal-gives-an-errror/195084/5 "2010-09-17T00:38:31Z")

</div>

> You didn’t call the ping? method in your example. You just called the  
> constructor.
> 
> > someone ï¿½know what the difference is between  
> > Net::Ping::TCP.new(‘localhost’)  
> > Net::Ping::External.new(‘localhost’)
> 
> The external ping uses your system’s ping command. The TCP ping tries  
> to connect to the host via a Ruby TCPSocket.
> 
> Regards,
> 
> Dan

thanks Dan  
indeed i mist the methode stupid off me  
thanks for the fast reply and the explanation

---

<div class="post-metadata">

**Author:** ![webwizart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@webwizart](https://www.ruby-forum.com/u/webwizart)\
**Post date:** [September 17, 2010, 12:26am UTC](https://www.ruby-forum.com/t/net-pingexternal-gives-an-errror/195084/6 "2010-09-17T00:26:52Z")

</div>

On Sep 16, 4:17 pm, Younes B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> else  
> puts ‘NO respons’  
> end
> 
> this is the output:  
> OK  
> OK  
> webwizartbe-iMac:balbaert younesbaghor$
> 
> 2 times ok even when the localhost is spelled wrong.

You didn’t call the ping? method in your example. You just called the  
constructor.

> someone know what the difference is between  
> Net::Ping::TCP.new(‘localhost’)  
> Net::Ping::External.new(‘localhost’)

The external ping uses your system’s ping command. The TCP ping tries  
to connect to the host via a Ruby TCPSocket.

Regards,

Dan
