Skip to content

Instantly share code, notes, and snippets.

@KINGSABRI
Created April 14, 2012 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KINGSABRI/2387540 to your computer and use it in GitHub Desktop.
Save KINGSABRI/2387540 to your computer and use it in GitHub Desktop.
Switch
#!/usr/bin/ruby
###################################################################
#### " _ _ _ _ ___ _ _ _ " ####
#### " | \| (_)_ _ (_)__ _ | __(_)_ _ _____ __ ____ _| | | " ####
#### " | .` | | ' \ | / _` | | _|| | '_/ -_) V V / _` | | | " ####
#### " |_|\_|_|_||_|/ \__,_| |_| |_|_| \___|\_/\_/\__,_|_|_| " ####
#### " |__/ " ####
###################################################################
#### Coded by: Sabry Saleh ####
#### Last update: ####
#### License: GPL3 ####
#### Version: 0.1 ####
###################################################################
#
# gem install net-scp colorize net-ssh net-scp net-telnet logger
#
gems = %w{rubygems colorize net/telnet logger} ; gems.each { |gem| require gem }
mark_Red = "[+]".red
mark_Green = "[+]".green
mark_yellow = "[+]".yellow
##################################
def logger
log = Logger.new('log.txt', 10, 1024000) # Filename: log.txt , Number of rotation: 10 , Rotation Size= 125MB
end
host = 'xx.xx.xx.xx'
user = "Username"
pass = "P@ssword"
port = 23
cmd = "display b int"
# hcmd = ["system-view" , "Int GigabitEthernet1/0/42" , "Un Shut" , "Dis b int GigabitEthernet1/0/42" , "quit"] #ifup
hcmd = ["system-view" , "Int GigabitEthernet1/0/42" , "Shut" , "Dis b int GigabitEthernet1/0/42"] #ifdown
s = Net::Telnet::new("Host" => host ,"Timeout" => 130)
s.puts(user) { |u| print u }
s.puts(pass) do |p|
print p
if p.inspect.include? "failed"
logger.info "Wrong Password!"
exit
end
if p.inspect.include? "<"
logger.info "Logged Successfully!"
end
end
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
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
# s.cmd(hcmd[5])
end # l3
end # l2
end # l1
end # l0
s.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment