[Courses] [Ruby] Lesson 0: Installing, References, and your first homework assignment

Chantal Rosmuller chantal at antenna.nl
Wed Nov 9 21:27:35 EST 2005


Hi I'm Chantal, I am a linux/freebsd/windows sysadmin at a small 
internet service provider. I am definitely not an experienced programmer 
but I like to write some bash scripts every now and then to make my life 
as a sysadmin easier and more fun, and I know some php. I'm interested 
in ruby because I want to learn a new programming language and a lot of 
people seem to be enthusiastic about it, I guess I am just curious. I 
want to learn a language in which I can write more sophisticated 
sysadmin tools in the future and I thought ruby might be a candidate (or 
perl but I can learn that some other time too). Well anyway, here's my 
homework, some code I wrote myself, I needed to configure an interface 
on an openbsd system for a whole ip range and it had to put something 
like this:

inet alias x.y.z.1 255.255.255.0
inet alias x.y.z.2 255.255.255.0

etc

I didn't want to type all of that so I wrote ipspitter.rb:
It basically takes a number to start with and adds one a number of times 
and keeps printing that, together with a string for the first three 
parts of the ip address and some text if you want

#!/usr/bin/ruby

puts "This is ipspitter"
puts "Which number do you want to start the range with?"

count = gets.to_i
sum = count

puts " How many ip addresses do you want?"

number = gets.to_i
number = number - 1
puts "Enter the first three parts of the ip-address (for example 
192.168.4. )"
range = gets.chomp

puts "Do you want to put some text in front of the ip-address? Put it here"
textbefore = gets.chomp

puts "Do you want to put some text after the ip-address? Put it here"
textafter = gets

puts textbefore + range + count.to_s + textafter

number.times do
       count +=1
       sum += count
       puts textbefore + range + count.to_s + textafter
end




More information about the Courses mailing list