예제 #1
0
    def get_config(self, list_of_commands, list_of_devices):
        device_output = {}

        for device in list_of_devices:
            outputs = []
            for command in list_of_commands:
                if not show_cmd_ssh(device, self.username, self.password,
                                    command):
                    return False
                for data in show_cmd_ssh(device, self.username, self.password,
                                         command):
                    outputs.append(data.strip('\r\n'))
            device_output[device] = outputs
        return device_output
예제 #2
0
    def cisco_interfaces_status(self):

        if self.device_type == "Cisco IOS":
            run_config = cisco.show_cmd_ssh(self.hostname, self.username,
                                            self.password, "show ip int brief")
        elif self.device_type == "Junos":
            run_config = cisco.show_cmd_ssh(self.hostname, self.username,
                                            self.password,
                                            "show interface terse")

        self.ptedit_cmd_output.clear()

        if run_config:
            for config in run_config:
                self.ptedit_cmd_output.appendPlainText(
                    config.replace("\r", "").strip('\n'))
예제 #3
0
    def cisco_show_run_section(self):

        section = self.edit_custom_command.text()

        if self.combo_device_type.currentText() == "Cisco IOS":
            if section:
                command = "Show run | section " + section
            else:
                command = "show run"
        elif self.combo_device_type.currentText() == "Junos":
            if self.display_set == True:
                command = "show configuration " + section + " | display set"
                self.display_set = False
            else:
                command = "show configuration " + section

        run_config = cisco.show_cmd_ssh(self.hostname, self.username,
                                        self.password, command)

        self.ptedit_cmd_output.clear()

        if run_config:
            for config in run_config:
                self.ptedit_cmd_output.appendPlainText(
                    config.replace("\r", "").strip('\n'))
        else:
            self.ptedit_cmd_output.appendPlainText(
                "No configurations found for this section")
예제 #4
0
    def cisco_show_run(self):

        if self.device_type == "Cisco IOS":
            command = "show run"
        elif self.device_type == "Junos":
            if self.display_set == True:
                command = "show configuration | display set"
                self.display_set = False
            else:
                command = "show configuration"

        run_config = cisco.show_cmd_ssh(self.hostname, self.username,
                                        self.password, command)

        self.ptedit_cmd_output.clear()
        for config in run_config:
            self.ptedit_cmd_output.appendPlainText(
                config.replace("\r", "").strip('\n'))
예제 #5
0
    def cisco_show_routing_table(self):

        if self.device_type == "Cisco IOS":
            command = "show ip route "
        elif self.device_type == "Junos":
            command = "show route "

        if self.edit_custom_command.text():
            command = command + self.edit_custom_command.text()

        run_config = cisco.show_cmd_ssh(self.hostname, self.username,
                                        self.password, command)

        self.ptedit_cmd_output.clear()

        if run_config:
            for config in run_config:
                self.ptedit_cmd_output.appendPlainText(
                    config.replace("\r", "").strip('\n'))
예제 #6
0
    def cisco_custom_command(self):

        if self.edit_custom_command.text():
            command = self.edit_custom_command.text()
        else:
            self.edit_custom_command.setPlaceholderText(
                "Please enter a command")
            return

        run_config = cisco.show_cmd_ssh(self.hostname, self.username,
                                        self.password, command)

        self.ptedit_cmd_output.clear()

        if run_config:
            for config in run_config:
                self.ptedit_cmd_output.appendPlainText(
                    config.replace("\r", "").strip('\n'))
        else:
            self.ptedit_cmd_output.appendPlainText("Invalid command")
예제 #7
0
    def cisco_show_cdp_neighbor(self):

        if self.device_type == "Cisco IOS":
            command = "show cdp neighbor "
        elif self.device_type == "Junos":
            command = "show lldp neighbor "

        if self.edit_custom_command.text():
            command = command + self.edit_custom_command.text()

        run_config = cisco.show_cmd_ssh(self.hostname, self.username,
                                        self.password, command)

        self.ptedit_cmd_output.clear()

        if run_config:
            for config in run_config:
                self.ptedit_cmd_output.appendPlainText(
                    config.replace("\r", "").strip('\n'))
        else:
            self.ptedit_cmd_output.appendPlainText("NO neighbors found")
예제 #8
0
    def cisco_show_arp(self):

        if self.device_type == "Cisco IOS":
            command = "show ip arp "
            if self.edit_custom_command.text():
                command = command + self.edit_custom_command.text()
        elif self.device_type == "Junos":
            command = "show arp "
            if self.edit_custom_command.text():
                command = command + "hostname " + self.edit_custom_command.text(
                )

        run_config = cisco.show_cmd_ssh(self.hostname, self.username,
                                        self.password, command)

        self.ptedit_cmd_output.clear()

        if run_config:
            for config in run_config:
                self.ptedit_cmd_output.appendPlainText(
                    config.replace("\r", "").strip('\n'))
        else:
            self.ptedit_cmd_output.appendPlainText(
                "No arp entry found for this host.")
예제 #9
0
    def pull_device_info(self):

        #print(self.btn_connect.text())

        #         if self.btn_connect.text() == "Disconnect":
        #             self.edit_username.setEnabled(True)
        #             self.edit_password.setEnabled(True)
        #             self.label.setText("")
        #             self.btn_connect.setText("Connect")

        self.hostname = self.edit_ip_add.text()
        self.protocol = self.combo_protocol.currentText()
        self.username = self.edit_username.text()
        self.password = self.edit_password.text()
        self.device_type = self.combo_device_type.currentText()
        device_type = self.combo_device_type.currentText()

        if cisco.connection_test_ssh(self.hostname, self.username,
                                     self.password) == True:

            # disable username/password fields
            self.edit_username.setEnabled(False)
            self.edit_password.setEnabled(False)
            # connected message instead of error
            self.label.setText("Connected")
            self.btn_connect.setEnabled(False)
            #self.btn_connect.setText("Disconnect")
            self.combo_device_type.setEnabled(False)

            if device_type == "Cisco IOS":

                device_hostname = cisco.show_cmd_ssh(self.hostname,
                                                     self.username,
                                                     self.password,
                                                     "show run | in hostname")
                device_hostname = device_hostname[0].split(' ')[1]
                self.lbl_hostname.setText(device_hostname)

                ios_version = cisco.show_cmd_ssh(self.hostname, self.username,
                                                 self.password,
                                                 "show version | in Version")
                ios_version = ios_version[0]
                self.lbl_ios_version.setText(ios_version)

                cpu_status = cisco.show_cmd_ssh(self.hostname, self.username,
                                                self.password,
                                                "show proc cpu | in CPU")
                cpu_status = cpu_status[0].strip('\n')
                self.lbl_cpu_utilization.setText(cpu_status)

                uptime = cisco.show_cmd_ssh(self.hostname, self.username,
                                            self.password,
                                            "show version | in time")
                uptime = uptime[0].strip('\n')
                self.lbl_uptime.setText(uptime)

            elif device_type == "Junos":
                device_hostname = cisco.show_cmd_ssh(
                    self.hostname, self.username, self.password,
                    "show version | match Hostname")
                device_hostname = device_hostname[0].split(' ')[1]
                self.lbl_hostname.setText(device_hostname)

                ios_version = "before"
                ios_version = cisco.show_cmd_ssh(
                    self.hostname, self.username, self.password,
                    'show version | match "Base OS Boot"')
                ios_version = ios_version[0]
                #print(ios_version)
                self.lbl_ios_version.setText(ios_version)

                uptime = cisco.show_cmd_ssh(self.hostname, self.username,
                                            self.password,
                                            "show system uptime")
                for output in uptime:
                    if "up" in output:
                        self.lbl_uptime.setText(output)

        else:
            self.label.setText(
                "Couldn't connect, Check username/password, connectivity to host"
            )
#!/usr/bin/env python3
# private classes
from cisco import show_cmd_ssh
# show_cmd_ssh(hostname, username, password, command):

device_ip = input("device name? ")
user_name = input("username: "******"device password: "******"Filename for commands to run: ")

list_of_commands = []
with open(filename) as read_file:
    for line in read_file:
        list_of_commands.append(line.strip('\n'))
print(list_of_commands)

with open(f"{device_ip}", "w") as file:
    for command in list_of_commands:
        result = show_cmd_ssh(device_ip, user_name, device_password, command)
        file.write('\n' + command + "\n")
        for data in result:
            file.write(data.strip('\r\n'))
            file.write("\n")