Skip to content

Instantly share code, notes, and snippets.

@autch
Created October 14, 2011 02:11
Show Gist options
  • Save autch/1286074 to your computer and use it in GitHub Desktop.
Save autch/1286074 to your computer and use it in GitHub Desktop.
RTX1000 のtelnetインタフェースからFW状況を取得してCSVで出力
#!/usr/bin/ruby1.9.1
# -*- coding: euc-jp -*-
require 'net/telnet'
RT_HOST = 'YOUR_RTX1000_ADDR'
RT_PW = 'YOUR_RTX1000_PASSWORD'
telnet = Net::Telnet.new("Host" => RT_HOST,
"Waittime" => 1,
"Prompt" => /^> \z/)
telnet.waitfor("Match" => /^Password: \z/in, "Timeout" => 1, "Waittime" => 3)
telnet.cmd(RT_PW)
telnet.cmd("console lines infinity")
out_buffer = ""
telnet.puts("show ip connection lan3")
telnet.waitfor("Match" => /^> \z/, "Timeout" => 30){|l| out_buffer << l }
telnet.puts("quit")
telnet.close
lines = out_buffer.split(/\n/).map{|l| l.strip }
while /^LAN3\[out\]/ !~ (line = lines.first) do
lines.shift
end
lines.shift
lines.each do |line|
puts line.split(/\s+/).map{|i| "\"#{i}\"" }.join(",")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment