Friday, December 14, 2007

rubby and caffee is grate two!

I like take times at cafee houses on lap coputer time. I try connect on webbing with no wires and it takes times away from fun times! so I make work from script in rubby! here it is for frends:

#!/usr/bin/ruby

nic = "eth1"


aps = Hash.new
essid = nil
`sudo iwlist #{nic} scan`.each do |line|
if line =~ /ESSID:(.*)/
essid = $1
elsif line =~ /Encryption\skey:(.*)/
encryption = $1
essid = nil if encryption == 'on'
elsif line =~ /Quality=(\d+)\/100/
quality = $1.to_i
aps[essid] = quality if essid
end
end

best = ""
last = 0
aps.each_pair do |essid,quality|
best = essid if quality > last
end

system("sudo iwconfig #{nic} essid #{best}")
system("sudo dhclient #{nic}")

aw yes! this make my coputer get from best webbing site faster! do it frendly time!

No comments: