Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Sunday, July 20, 2008

Rmagick - Ruby image library.

I have used the Rmagick to create the gif2led, which is used for my hardware led projects. You can find more detail at http://www.bitartist.org/2008/06/gif2led-released-and-with-my-led-egg.html

It is a very simple application, and involved some manipulations on animated gif with Rmagick. The code is simple to read if you are interested in working on animated gif in Ruby.

Thursday, May 22, 2008

Ping echo check in Ruby, a dummy port scanner

Ping library in Ruby is fun to use,
it is easy to make it as a small port scanner

require "ping"

if ARGV.length != 3
puts "Usage: pingb machine_domain min max"
exit 0
end

for port in (ARGV[1].to_i..ARGV[2].to_i) do
if Ping.pingecho(ARGV[0],1,port) then
puts "Port #{port} open"
end
end

$ruby pingecho.rb slashdots.org 80 100
Port 80 open

Command line arguments in Ruby.

Using the array: ARGV

Example:

puts "No. of arguments:" << ARGV.length.to_s

puts "Loop elements"
for options in ARGV do
puts options
end

puts "Loop index"
for i in 0..ARGV.length-1
puts "#{i} #{ARGV[i]}"
end

$ ruby testcmd.rb one two three
No. of arguments:3
Loop elements
one
two
three
Loop index
0 one
1 two
2 three