A
Andrea Campagna
Hi to all,
i've done a ruby script that restart a VoIP network device. The code i s
below:
url = URI.parse('http://192.168.0.111/dologin.htm')
response=Net::HTTP.start(url.host, url.port) {|http|
req = Net::HTTP:ost.new(url.path)
req.set_form_data({'P2'=>'password', 'Login' => 'login', 'gnkey' =>
'0b82'}, '&')
res=http.request(req)
puts res
cookie=res.get_fields('Set-Cookie')
cookie=cookie.to_s.match(/SessionId=((.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.))/).to_s
req=Net::HTTP::Get.new('/rs.htm')
req.add_field('Cookie',cookie)
http.request(req)
}
case response
when Net::HTTPSuccess then status=1
when Net::HTTPClientError then status=2
when Net::HTTPServerError then status=2
when Net::HTTPUnknownResponse then status=2
end
I've problems to manage these errors:
when the device is not connected i get an (Errno::EHOSTUNREACH) or the
script seems freezed....
Any suggetion???
Thanks in advance
Andrea
i've done a ruby script that restart a VoIP network device. The code i s
below:
url = URI.parse('http://192.168.0.111/dologin.htm')
response=Net::HTTP.start(url.host, url.port) {|http|
req = Net::HTTP:ost.new(url.path)
req.set_form_data({'P2'=>'password', 'Login' => 'login', 'gnkey' =>
'0b82'}, '&')
res=http.request(req)
puts res
cookie=res.get_fields('Set-Cookie')
cookie=cookie.to_s.match(/SessionId=((.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.))/).to_s
req=Net::HTTP::Get.new('/rs.htm')
req.add_field('Cookie',cookie)
http.request(req)
}
case response
when Net::HTTPSuccess then status=1
when Net::HTTPClientError then status=2
when Net::HTTPServerError then status=2
when Net::HTTPUnknownResponse then status=2
end
I've problems to manage these errors:
when the device is not connected i get an (Errno::EHOSTUNREACH) or the
script seems freezed....
Any suggetion???
Thanks in advance
Andrea