Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- gems = %w{rubygems net/ssh/telnet net/telnet logger} ; gems.each { |gem| require gem }
- logger = Logger.new('logs/ninjaFW.log', 10, 1024000) # Filename: ninjaFW.log , Number of rotation: 10 , Rotation Size= 125MB
- USER = "Spare"
- PASS = "Sabry321"
- PORT = 23
- class Connect
- attr_accessor :switch
- def initialize(switch)
- @switch = switch
- # puts "Connect #{switch.switch_type.name}"
- if switch.switch_type.name == HP
- hp_connect(switch)
- elsif switch.switch_type.name == HU
- huwaei_connect(switch)
- end
- end
- # s = Net::Telnet::new("Host" => switch.ip ,"Port" => PORT ,"Timeout" => 130)
- def hp_connect(switch)
- # s.write "\r\n" # "Press any key to continue"
- # s.puts(USER) { |u| print u }
- # if s.puts(PASS) { |p| print p }
- # inspect.include? "Invalid password"
- # logger.info "Wrong Password!"
- # exit
- # else
- # logger.info "Logged in Successfully!"
- # end
- # #--> Let's to execute
- # s.cmd(hpcmd[0]) do |l0| # Priv escalation
- # print l0
- # s.cmd(hpcmd[1]) do |l1| # Interface Up
- # print l1
- # s.cmd(hpcmd[3]) do |l2| # ifstatus
- # if l2.inspect.include? "Yes"
- # logger.info "HP Interface is UP now!"
- # elsif l2.inspect.include? "No"
- # logger.info "HP Interface is Down now!"
- # end
- # if s.cmd(hpcmd[5]).inspect.include? "Do you want to log out"
- # s.print "y"
- # end
- # if s.cmd(hpcmd[5]).inspect.include? "Do you want to save current configuration"
- # logger.info "Configuration has been saved"
- # s.print "y"
- # end
- # end # l2
- # end # l1
- # end # l0
- #
- puts "Customer name: #{switch.cust_name}"
- puts "Switch Type: #{switch.switch_type.name}"
- puts "Switch IP: #{switch.ip}"
- puts switch.switch_type.cmd["sudo"]
- end
- def huwaei_connect(switch)
- # s.puts(USER) { |u| print u }
- # s.puts(PASS) do |p|
- # print p
- # if p.inspect.include? "Invalid password"
- # logger.info "Wrong Password!"
- # exit
- # else
- # logger.info "Logged Successfully!"
- # end
- # end
- # #--> Let's to execute
- # s.cmd(hcmd[0]) do |l0| # Priv escalation
- # print l0
- # s.cmd(hcmd[1]) do |l1| # Interface config level
- # print l1
- # s.cmd(hcmd[2]) do |l2| # ifup/ifdown s.cmd(sw1.type.cmd[])
- # print l2
- # s.cmd(hcmd[3]) do |l3| # ifstatus
- # print l3
- # if l3.inspect.include? "UP"
- # logger.info "Interface is UP!"
- # elsif l3.inspect.include? "ADM"
- # logger.info "Interface is Down!"
- # end
- # end # l3
- # end # l2
- # end # l1
- # end # l0
- puts "Customer name: #{switch.cust_name}"
- puts "Switch Type: #{switch.switch_type.name}"
- puts "Switch IP: #{switch.ip}"
- puts switch.switch_type.cmd["sudo"]
- end
- end
Add Comment
Please, Sign In to add comment