require 'net-telnet' require 'net/ssh' require 'date' class CSRtelnet_1 attr_accessor :iwag1_host, :iwag_username, :iwag_password def initialize(iwag1_host, iwag_username, iwag_password) @iwag1_host = iwag1_host @iwag_username = iwag_username @iwag_password = iwag_password end def get_subs_mac2_1(ipaddress) subscribers_mac = "" #begin dump ="" connection = Net::Telnet.new( "Host" => iwag1_host, "Timeout" => false, "Prompt" => /.*/ ) { |str| } connection.login({ "Name" => iwag_username, "Password" => iwag_password, "LoginPrompt" => /Username:/ }) { |str| } connection.cmd("show ip dhcp binding #{ipaddress}") { |c| p c dump << c } connection.close as = dump.split("\n") p as reer = as[4].split(" ") ma = reer[1].to_s.upcase pos = ma[0]+ma[1] if pos == '01' subscribers_mac = ma[2]+ma[3]+":"+ma[5]+ma[6]+":"+ma[7]+ma[8]+":"+ma[10]+ma[11]+":"+ma[12]+ma[13]+":"+ma[15]+ma[16] else subscribers_mac = ma[0]+ma[1]+":"+ma[2]+ma[3]+":"+ma[5]+ma[6]+":"+ma[7]+ma[8]+":"+ma[10]+ma[11]+":"+ma[12]+ma[13] end #rescue # subscribers_mac = "unknown" #end subscribers_mac end #test function. Not used def get_iwag_info_ssh_1(ipaddress) p DateTime.now Net::SSH.start(iwag1_host, iwag_username, :password => iwag_password) do |ssh| result = ssh.exec!("show ip dhcp binding #{ipaddress}\n") p result end p DateTime.now end def return_iwag_access_interface_1(ipaddress) host_iwag = iwag1_host username_iwag = iwag_username password_iwag = iwag_password answer ="" dump ="" begin connection = Net::Telnet.new("Host" => host_iwag, "Timeout" => false, "Prompt" => /.*/) {|str| print str} connection.login({"Name" => username_iwag, "Password" => password_iwag, "LoginPrompt" => /Username:/}) {|str| print str} connection.cmd("show ip dhcp binding #{ipaddress}") { |c| dump << c } connection.close as = dump.split("\n") if as[4] != nil && as[3] != "" access_interface = as[4].gsub!(" ", "").split(" ").last return access_interface else answer = 'false' return answer end rescue begin connection = Net::Telnet.new('Host' => host_iwag, 'Timeout' => false, 'Prompt' => /.*/) {|str| print str} connection.login({'Name' => username_iwag, 'Password' => password_iwag, 'LoginPrompt' => /Username:/}) {|str| print str} connection.cmd("show ip dhcp binding #{ipaddress}") { |c| dump << c } connection.close as = dump.split("\n") if as[4] != nil && as[3] != "" access_interface = as[4].gsub!(" ", "").split(" ").last return access_interface else answer ='false' return answer end rescue return 'unknown' end end end end