Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import sys
- import os
- script_path = os.path.dirname(os.path.realpath(__file__))
- sys.path.insert(0, script_path+'/Lib/site-packages')
- from pexpect import pxssh
- # ------------------- START -------------------- #
- IP = ""
- PASS = ""
- PASS1 = "xxxxxx"
- PASS2 = "xxxxxx"
- PASS3 = "xxxxxx"
- PASS4 = "xxxxxx"
- OUTPUT = ""
- choice = ""
- # Main definition - constants
- menu_actions = {}
- # =======================
- # MENUS FUNCTIONS
- # =======================
- # Main menu
- def main_menu():
- os.system('clear')
- print "Result of last Query:"
- print "--------------------"
- print OUTPUT
- print "\n"
- print "Welcome to RAD Makro v0.1\n"
- print "Please make a selection:"
- print "1. Show Port Status"
- print "2. Activate/Deactivate Ports"
- print "\n0. Quit"
- choice = raw_input(" >> ")
- exec_menu(choice)
- return
- # Execute menu
- def exec_menu(choice):
- os.system('clear')
- ch = choice.lower()
- if ch == '':
- menu_actions['main_menu']()
- else:
- try:
- menu_actions[ch]()
- except KeyError:
- print "Invalid selection, please try again.\n"
- menu_actions['main_menu']()
- return
- # Menu 2
- def menu2():
- print "Hello Menu 2 !\n"
- print "9. Back"
- print "0. Quit"
- choice = raw_input(" >> ")
- exec_menu(choice)
- return
- # Back to main menu
- def back():
- menu_actions['main_menu']()
- # -------- Menu Tasks --------- #
- # Show Port Status
- def shwPrt(SSH):
- SSH.sendline("configure system clock domain 1 source 1")
- SSH.sendline("show status")
- SSH.prompt()
- OUTPUT = SSH.before
- exec_menu(choice)
- def sshconnect (SSH):
- os.system('clear')
- SSH = pxssh.pxssh()
- USER = "su"
- while True:
- try:
- PASS = PASS1
- print "Logging in...\n"
- SSH.login(IP, USER, PASS, auto_prompt_reset=False)
- break
- except:
- print "Trying another Password..."
- PASS = PASS2
- SSH.login(IP, USER, PASS, auto_prompt_reset=False)
- print "The Password was %s. this should not be! Consider changing at as soon as possible!\n" % PASS
- break
- try:
- PASS = PASS3
- print "Trying another Password..."
- SSH.login(IP, USER, PASS, auto_prompt_reset=False)
- print "The Password was %s. this should not be! Consider changing at as soon as possible!\n" % PASS
- break
- except:
- PASS = PASS4
- print "Trying another Password. This is the last try!"
- SSH.login(IP, USER, PASS, auto_prompt_reset=False)
- print "The Password was %s. this should not be! Consider changing at as soon as possible!\n" % PASS
- break
- SSH.PROMPT = ".*?(#) $" #Alternative: "(#) $"
- #SSH.PROMPT = ".*?(#) $" # "(#) $"
- #ssh.sendline("configure system clock domain 1 source 1")
- #ssh.prompt()
- #ssh.sendline("show status")
- #ssh.prompt()
- #print("Commands executed")
- #cmd_return = ssh.before
- #print("Command returned: " + cmd_return)
- #i = cmd_return.index('\n')
- #print(cmd_return[i+i:])
- #ssh.sendline("exit all")
- #ssh.sendline("logout")
- #ssh.logout()
- # Exit program
- def exit():
- sys.exit()
- # =======================
- # MENUS DEFINITIONS
- # =======================
- # Menu definition
- menu_actions = {
- 'main_menu': main_menu,
- '1': shwPrt(SSH),
- '2': menu2,
- '9': back,
- '0': exit,
- }
- # =======================
- # MAIN PROGRAM
- # =======================
- # Main Program
- os.system('clear')
- if __name__ == "__main__":
- # Validate IP and Launch Main Menu
- print "Please enter the IP you want to connect to:"
- IP = raw_input('>> ')
- a = IP.split('.')
- if len(a) != 4:
- print "Invalid IP address!\n"
- sys.exit()
- for x in a:
- if not x.isdigit():
- print "Invalid IP address!\n"
- sys.exit()
- i = int(x)
- if i < 0 or i > 255:
- print "Invalid IP address!\n"
- sys.exit()
- print "Trying to reach host with IP %s..." % IP
- HOST_UP = True if os.system("ping -c 3 " + IP) is 0 else False
- if HOST_UP == True:
- sshconnect()
- main_menu()
- else:
- print "Host with IP address %s is dead!" % IP
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement