starting address

54 views
Skip to first unread message

retr0h

unread,
Feb 27, 2012, 10:25:47 PM2/27/12
to Ruby IPAddress
I have the first 50 IPs reserved in a subnet we are using.
Is it possible for each or each_host to start at the 50th address?

5 addr = IPAddress.parse "192.168.112.50/20"
6
7
8 addr.each do |i|
9 puts i
10 exit
11 end


### output

192.168.112.0

Any ideas?

Thanks -
John

Marco Ceresa

unread,
Feb 28, 2012, 2:47:06 AM2/28/12
to ruby-ip...@googlegroups.com
On Tue, Feb 28, 2012 at 4:25 AM, retr0h <set...@gmail.com> wrote:

> I have the first 50 IPs reserved in a subnet we are using.
> Is it possible for each or each_host to start at the 50th address?

Hello John,

here is what I would do

>  5 addr = IPAddress.parse "192.168.112.50/20"

addr.to_a[49..-1].each do |i|
# do your stuff
end

if you want the 50th address, or

addr.to_a[50..-2].each do |i|
# do your stuff
end

if you want the 50th host.

retr0h

unread,
Feb 28, 2012, 4:01:55 PM2/28/12
to Ruby IPAddress
Thanks marco.

I was debating creating an array, and doing what I wished with it.
Thanks again.

John

On Feb 27, 11:47 pm, Marco Ceresa <cer...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages