Example #1
0
def qytang_remote_login(ip):
    for x in ip:
        if qytang_ping(x):
            print(x, '通!')
            print(qytang_ssh(x, username='******', password='******'))
        else:
            print(x, '不通!')
Example #2
0
def ping_and_ssh(ip_list, username, password, cmd):
    for ip in ip_list:
        ping_result = qytang_ping(ip)
        if ping_result[1] == 1:
            print(ping_result[0], '可达!')
            print('登录', ping_result[0], '执行命令', cmd, '回显结果如下:')
            print(qytang_ssh(ping_result[0], username=username, password=password, cmd=cmd))
        else:
            print(ping_result[0], '不可达!')
Example #3
0
def qytang_get_config(ip, username='******', password='******'):
    try:
        device_config_raw = qytang_ssh(ip, username, password, cmd='show run')
        split_result = re.split(r'\r\nhostname \S+\r\n', device_config_raw)
        device_config = device_config_raw.replace(split_result[0], '').strip()
        return device_config
        # cmd = 'show running-config | begin hostname'  # 教主的re,是为了用正则表达式去获取这个命令的输出内容吗?
        # config = qytang_ssh(ip, username, password, cmd=cmd)
        # return config

    except Exception:
        return
def get_config_md5(ip, username, password):
    run_config_raw = qytang_ssh(ip, username, password)
    where = run_config_raw.find('hostname')
    run_config_raw = run_config_raw[where:]
    # print(show_run)
    run_config_raw = re.split('\r*\n+!*', run_config_raw)
    run_config_raw = [x for x in run_config_raw if x != '' and x != ' ']
    run_config_new = '\n'.join(run_config_raw)

    m = hashlib.md5()
    m.update(run_config_new.encode())
    md5_value = m.hexdigest()
    # print(run_config_new)
    return run_config_new, md5_value
Example #5
0
def qytang_get_if(*ips, username='******', password='******'):
    device_if_dict = {}
    for ip in ips:
        single_device_dict = {}  # put in the correct location.
        ping_result = qytang_ping(ip)
        if ping_result[1]:
            ssh_get_result = qytang_ssh(ip,
                                        username,
                                        password,
                                        cmd='show ip interface brief')
            items = ssh_get_result.split('\n')
            for item in items:
                re_result = re.match(
                    '(\w*)\s+(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})\s+(\w*)\s+(\w*)\s+(\w*)\s+(\w*)',
                    item)
                if re_result:
                    if_name = re_result.groups()[0]
                    if_ip = re_result.groups()[1]
                    single_if_dict = {if_name: if_ip}
                    single_device_dict.update(single_if_dict)
        device_if_dict.update({ip: single_device_dict})
    return device_if_dict
Example #6
0
from paramiko_ssh import qytang_ssh

if __name__ == '__main__':
    from argparse import ArgumentParser

    usage = 'python Simple_SSH_Client -i ipaddress -u username -p password -c command'

    parser = ArgumentParser(usage=usage)

    parser.add_argument('-i','--ipaddress',dest='ipaddress',help='SSH Sever',default='192.168.220.129',type=str)
    parser.add_argument('-u','--username', dest='username', help='SSH Username', default='root', type=str)
    parser.add_argument('-p','--password', dest='password', help='SSH Password', default='Cisc0123', type=str)
    parser.add_argument('-c','--command', dest='command', help='Shell Command', default='ls', type=str)

    args = parser.parse_args()

    print(qytang_ssh(args.ipaddress,args.username,args.password,cmd=args.command))
Example #7
0
    # 改变文本的大小
    # 方法是把每一个text遍历。调用set_size方法设置它的属性
    for l in label_text:
        l.set_size = 30
    for p in percent_text:
        p.set_size = 20
    # 设置x,y轴刻度一致,这样的饼图才能是圆的
    plt.axis('equal')
    plt.legend()
    plt.show()


if __name__ == "__main__":
    result_show = qytang_ssh(
        '192.168.11.120',
        'admin',
        'cisco',
        cmd='show flow monitor name qytang-monitor  cache format table')
    print(result_show)
    result_show = result_show.split('\n')
    result_show = [x for x in result_show if x != '' and x != ' ']
    counters = []
    protocols = []
    protocols_new = []
    for x in result_show:
        if re.findall('APP NAME', x):
            a = result_show.index(x)
            result_show_new = result_show[12:]
            # print(result_show_new)
    for x in result_show_new:
        if re.match('(\w+\s*\w+)\s+(\d+)\r', x).groups():
Example #8
0
#!/usr/bin/env python3
# -*- coding=utf-8 -*-

from paramiko_ssh import qytang_ssh


if __name__ == '__main__':
    from argparse import ArgumentParser

    usage = 'usage:python Simple_SSH_Client -i ipaddr -u username -p password -c command'

    parser = ArgumentParser(usage)

    parser.add_argument("-i", "--ipaddr", dest='ipaddr', help='SSH Server', default='192.168.11.40')
    parser.add_argument("-u", "--username", dest='username', help='SSH Username', default='admin')
    parser.add_argument("-p", "--password", dest='password', help='SSH Password', default='root')
    parser.add_argument("-c", "--command", dest='command', help='Shell Command', default='pwd')

    a = parser.parse_args()

    print(qytang_ssh(a.ipaddr, a.username, a.password, a.command))