# Pinging a host

**URL:** <https://www.ruby-forum.com/t/pinging-a-host/92356>\
**Category:** Rails\
**Created:** [April 18, 2007, 5:34pm UTC](https://www.ruby-forum.com/t/pinging-a-host/92356 "2007-04-18T17:34:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raymond\_Ward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@Raymond\_Ward](https://www.ruby-forum.com/u/Raymond_Ward)\
**Post date:** [April 18, 2007, 5:34pm UTC](https://www.ruby-forum.com/t/pinging-a-host/92356/1 "2007-04-18T17:34:25Z")

</div>

Hello,

I am working on an App and am trying to return a page with the status of  
a host (up/down). The host IP addresses are taken from a database and  
then pinged using ping.rb. The code works if typed in irb but when  
done from inside Rails, it always returns false.

The code is called from list.rhtml by

## \<%=h firewall.host\_up(firewall.ip4\_addr) %\>

host\_up is in the model rb script as  
def host\_up(ip4\_addr)  
require “ping.rb”  
ping\_obj =  
Ping.pingecho(ip4\_addr,timeout=5,service=“echo”)  
if ping\_obj == false  
is\_up = “Down”  
end  
if ping\_obj == true  
is\_up = “UP”  
end  
ret\_value ="device " + ip4\_addr + " is "+ is\_up  
return ret\_value  
end

The code seems to execute (if a put a breakpoint call in host\_up, it  
gets called) just does not return a true when the host is up. Using  
tcpdump, I can see that is does not ever actually try to send out  
packets.

Thanks for any ideas or suggestions you might have.  
Ray

–  
Ray Ward  
Ward Technologies, LLC  
removed\_email\_address@domain.invalid  
630 544-2999

---

<div class="post-metadata">

**Author:** ![Raymond\_Ward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@Raymond\_Ward](https://www.ruby-forum.com/u/Raymond_Ward)\
**Post date:** [April 18, 2007, 5:43pm UTC](https://www.ruby-forum.com/t/pinging-a-host/92356/2 "2007-04-18T17:43:26Z")

</div>

> I am working on an App and am trying to return a page with the status of  
> a host (up/down). The host IP addresses are taken from a database and  
> then pinged using ping.rb. The code works if typed in irb but when  
> done from inside Rails, it always returns false.

- Are you running irb on the same machine as Rails?
- Any change you are inside a FreeBSD jail on the Rails machine?
- Are there any error messages you can get out of the Ping library?
- What about using script/console? Does that fail?
- Are the users running irb and Rails different? Or the same?
- What does ping.rb look like? Any chance it’s making a system call to  
the OS ping (which might fail if Rails user has no shell say)?

-p

---

<div class="post-metadata">

**Author:** ![Raymond\_Ward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@Raymond\_Ward](https://www.ruby-forum.com/u/Raymond_Ward)\
**Post date:** [April 18, 2007, 6:50pm UTC](https://www.ruby-forum.com/t/pinging-a-host/92356/3 "2007-04-18T18:50:37Z")

</div>

-irb was run from the same machine with the same user.  
-I thought of the jail idea since my development box is an OpenBSD  
machine but I moved it to a windows box and it did the same thing  
(running from irb still worked).  
-no errors that I can see.  
-Just tried, it works from script/console  
-users are the same

- ping.rb calls socket. I did not look into socket.

Philip H. wrote:

> - Are the users running irb and Rails different? Or the same?
> 
> > ## host\_up is in the model rb script as return ret\_value
> 
> * * *
> 
> This email has been scanned by the MessageLabs Email Security System.  
> For more information please visit [Email Security](http://www.messagelabs.com/email)
> 
> * * *

–  
Ray Ward  
Ward Technologies, LLC  
removed\_email\_address@domain.invalid  
630 544-2999
