Guest User

Untitled

a guest
Sep 28th, 2018
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. gems = %w{rubygems net/ssh/telnet net/telnet logger} ; gems.each { |gem| require gem }
  4. logger = Logger.new('logs/ninjaFW.log', 10, 1024000) # Filename: ninjaFW.log , Number of rotation: 10 , Rotation Size= 125MB
  5.  
  6. USER = "Spare"
  7. PASS = "Sabry321"
  8. PORT = 23
  9.  
  10.  
  11. class Connect
  12. attr_accessor :switch
  13.  
  14. def initialize(switch)
  15. @switch = switch
  16. # puts "Connect #{switch.switch_type.name}"
  17. if switch.switch_type.name == HP
  18. hp_connect(switch)
  19. elsif switch.switch_type.name == HU
  20. huwaei_connect(switch)
  21. end
  22.  
  23. end
  24.  
  25. # s = Net::Telnet::new("Host" => switch.ip ,"Port" => PORT ,"Timeout" => 130)
  26.  
  27. def hp_connect(switch)
  28.  
  29. # s.write "\r\n" # "Press any key to continue"
  30. # s.puts(USER) { |u| print u }
  31. # if s.puts(PASS) { |p| print p }
  32. # inspect.include? "Invalid password"
  33. # logger.info "Wrong Password!"
  34. # exit
  35. # else
  36. # logger.info "Logged in Successfully!"
  37. # end
  38. # #--> Let's to execute
  39. # s.cmd(hpcmd[0]) do |l0| # Priv escalation
  40. # print l0
  41. # s.cmd(hpcmd[1]) do |l1| # Interface Up
  42. # print l1
  43. # s.cmd(hpcmd[3]) do |l2| # ifstatus
  44. # if l2.inspect.include? "Yes"
  45. # logger.info "HP Interface is UP now!"
  46. # elsif l2.inspect.include? "No"
  47. # logger.info "HP Interface is Down now!"
  48. # end
  49. # if s.cmd(hpcmd[5]).inspect.include? "Do you want to log out"
  50. # s.print "y"
  51. # end
  52. # if s.cmd(hpcmd[5]).inspect.include? "Do you want to save current configuration"
  53. # logger.info "Configuration has been saved"
  54. # s.print "y"
  55. # end
  56. # end # l2
  57. # end # l1
  58. # end # l0
  59. #
  60. puts "Customer name: #{switch.cust_name}"
  61. puts "Switch Type: #{switch.switch_type.name}"
  62. puts "Switch IP: #{switch.ip}"
  63. puts switch.switch_type.cmd["sudo"]
  64. end
  65.  
  66. def huwaei_connect(switch)
  67.  
  68. # s.puts(USER) { |u| print u }
  69. # s.puts(PASS) do |p|
  70. # print p
  71. # if p.inspect.include? "Invalid password"
  72. # logger.info "Wrong Password!"
  73. # exit
  74. # else
  75. # logger.info "Logged Successfully!"
  76. # end
  77. # end
  78. # #--> Let's to execute
  79. # s.cmd(hcmd[0]) do |l0| # Priv escalation
  80. # print l0
  81. # s.cmd(hcmd[1]) do |l1| # Interface config level
  82. # print l1
  83. # s.cmd(hcmd[2]) do |l2| # ifup/ifdown s.cmd(sw1.type.cmd[])
  84. # print l2
  85. # s.cmd(hcmd[3]) do |l3| # ifstatus
  86. # print l3
  87. # if l3.inspect.include? "UP"
  88. # logger.info "Interface is UP!"
  89. # elsif l3.inspect.include? "ADM"
  90. # logger.info "Interface is Down!"
  91. # end
  92. # end # l3
  93. # end # l2
  94. # end # l1
  95. # end # l0
  96.  
  97. puts "Customer name: #{switch.cust_name}"
  98. puts "Switch Type: #{switch.switch_type.name}"
  99. puts "Switch IP: #{switch.ip}"
  100. puts switch.switch_type.cmd["sudo"]
  101. end
  102.  
  103. end
Add Comment
Please, Sign In to add comment