From: Brian Candler Date: 2009-03-02T06:12:02+09:00 Subject: Re: Gets the broadcast address of an IP address Eleanor McHugh wrote: > On 28 Feb 2009, at 22:49, Hassan Schroeder wrote: >>> The simplest way to do it is to use a regex to change the last term >>> in the >>> quad: >>> >>> IPSocket.getaddress(Socket.gethostname).gsub!(/.\d{1,3}$/, '.255') >> >> Simple but not necessarily correct :-) >> >> > > > > True, but I'm not sure the general case is so easy on the eye ;p This is messier than it should be, but: require 'ipaddr' n = IPAddr.new("192.168.0.101/24") p n | (~n.instance_variable_get(:@mask_addr) & IPAddr::IN4MASK) Or maybe you could just broadcast to the all-ones address (255.255.255.255) -- Posted via http://www.ruby-forum.com/.