Skip to content

Instantly share code, notes, and snippets.

@yuuki
Created June 11, 2011 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuuki/1020768 to your computer and use it in GitHub Desktop.
Save yuuki/1020768 to your computer and use it in GitHub Desktop.
Osaka-u Wireless LAN Login with CLI
#! /usr/bin/env ruby
# -*- coding:utf-8 -*-
require "logger"
require "mechanize"
$url = "https://login.odins.osaka-u.ac.jp/login.gsp"
$uid = "your uid"
$passwd = "your passwd"
def logined?(page)
return page.at('input[value="Logout"]') != nil
end
def main()
agent = Mechanize.new {|a| a.log=Logger.new('access.log')}
begin
agent.get($url)
if logined?(agent.page) == true then
$stderr.puts "alreay logined"
exit
end
form = agent.page.forms[0]
form.field_with(:name => 'user').value = $uid
form.field_with(:name => 'pass').value = $passwd
form.click_button
if logined?(agent.page) == false then
$stderr.puts "error: failed to login"
exit
end
rescue Timeout::Error
$stderr.puts "timeout: retry"
retry
end
puts "login success"
end
if __FILE__ == $0 then
main()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment