Esempio n. 1
0
def do_test(test_case):
    host = test_case["hostname"]
    expected = test_case["output"]
    connection = test_case.get("connection", "ssh")

    hash = os.environ["SHA"]
    binary = "ipctool-{}".format(hash)
    durl = "openipc.s3-eu-west-1.amazonaws.com/{}".format(binary)

    if connection == "telnet":
        UGET = "/tmp/uget"
        proxy = test_case.get("proxy")
        proxy_type = test_case.get("proxy_type", None)
        t = Telnet(host, debug=False, proxy_type=proxy_type, proxy=proxy)
        t.login()
        if not t.file_exists(UGET):
            t.upload_uget()
        output = t.run_command(UGET + " run " + durl).splitlines()
        t.close()
        assert output == expected

    elif connection == "ssh":
        run_cmd = "cd /tmp; rm -f {0}; wget -q http://{1}; chmod +x {0}; ./{0}; rm {0}".format(
            binary, durl)
        with Popen(["ssh", "root@{}".format(host), run_cmd],
                   stdout=PIPE) as proc:
            output = [
                i.decode("utf-8") for i in proc.stdout.read().splitlines()
            ]
            assert output == expected
Esempio n. 2
0
def set_ssh(device):
    cfgs = render_temp(device)

    tn = Telnet(host="172.20.0.1",
                port=device.get("port"),
                device_type="ios",
                debug=True)
    tn.send_config_set(cfgs)
Esempio n. 3
0
 def __init__(self, view):
     self.view = view
     #view.connection = self
     self.view.setConnection(self)
     #The following will be used by Telnet instance
     self.protocol = optionLogTelnetProtocol(self)
     Telnet.__init__(self)
     self.negotiationMap[chr(24)] = self.sendTermType
     self.negotiationMap[chr(0x1f)] = self.sendWindowSize
Esempio n. 4
0
def get_hostname(device):
    device_type = ""
    if "xrv" in device.get("hostname"):
        device_type = "iosxr"
    if "IOS" in device.get("hostname"):
        device_type = "ios"
    tn = Telnet("172.20.0.1",
                port=device.get("port"),
                device_type=device_type,
                debug=True)
    tn.config_hostname(device.get("hostname"))
Esempio n. 5
0
def setmgt_ip(d):
    device_type =""
    if "xrv" in d.get("hostname"):
        device_type = "iosxr"
        tn = Telnet(host="172.20.0.1", port=d.get("port"), device_type=device_type, debug=True)
        cfgs_list = []
        cfgs_list.append("interface mgmtEth 0/0/CPU0/0")
        cfgs_list.append("no shutdown")
        cfgs_list.append("ipv4 address %s 255.255.0.0" %d.get("mgt_ip"))
Esempio n. 6
0
    },
    {
        'port': 33301,
        'hostname': 'vIOS21',
        'username': '******',
        'password': '******',
        "mgt_ip": "172.20.3.121"
    },
]

for d in devices_info:
    device_type = ""
    if "xrv" in d.get("hostname"):
        device_type = "iosxr"
        tn = Telnet(host="172.20.0.1",
                    port=d.get("port"),
                    device_type=device_type,
                    debug=True)
        cfgs_list = []
        cfgs_list.append("interface mgmtEth 0/0/CPU0/0")
        cfgs_list.append("interface mgmtEth 0/0/CPU0/0")

        tn.send_config_set(cfgs_list)

    if "IOS" in d.get("hostname"):
        device_type = "ios"
        tn = Telnet(host="172.20.0.1",
                    port=d.get("port"),
                    device_type=device_type,
                    debug=True)
Esempio n. 7
0
        'password': '******',
        "mgt_ip": "172.20.3.119"
    },
    {
        'port': 33300,
        'hostname': 'vIOS20',
        'username': '******',
        'password': '******',
        "mgt_ip": "172.20.3.120"
    },
    {
        'port': 33301,
        'hostname': 'vIOS21',
        'username': '******',
        'password': '******',
        "mgt_ip": "172.20.3.121"
    },
]

for d in devices_info:
    device_type = ""
    if "xrv" in d.get("hostname"):
        device_type = "iosxr"
    if "IOS" in d.get("hostname"):
        device_type = "ios"
    tn = Telnet(host="172.20.0.1",
                port=d.get("port"),
                device_type=device_type,
                debug=True)
    tn.config_hostname(d.get("hostname"))
Esempio n. 8
0
from flask import Flask
from flask.globals import request
from telnet import Telnet
app = Flask(__name__)

TN = Telnet()

@app.route('/')
def hello_world():
    return 'Hello, World!'

@app.route('/login/<string:hostname>')
def login(hostname):
    return TN.login_no_passwd(hostname)

@app.route('/command/<string:hostname>',methods=['POST'])
def send_command(hostname):

    try:
        cmd = request.get_json()['cmd']
        
        msg = TN.run_cmd(hostname, cmd)
        return msg

    except Exception:
        return {'data': None},400


@app.route('/logout/<string:ip>')
def logout(ip):
    return TN.logout(ip)
Esempio n. 9
0
File: pyauto.py Progetto: vhsja/EDLP
 def all(self):
     app = pyauto()
     c = control()
     s = SSH()
     https = HTTPSControl()
     t = Telnet()
     hostname = socket.getfqdn(socket.gethostname())
     ipaddr = socket.gethostbyname(hostname)
     app.h0()
     time.sleep(5)
     app.h1()
     time.sleep(5)
     app.h11check()
     time.sleep(5)
     app.h2()
     time.sleep(5)
     app.h22check()
     time.sleep(5)
     app.h3check()
     time.sleep(5)
     c.sftp_up()
     time.sleep(5)
     app.h44check()
     time.sleep(5)
     if ipaddr == '172.24.83.44':
         app.h5check()
         time.sleep(5)
     if ipaddr == '172.24.83.44':
         app.h7check()
         time.sleep(5)
     app.h8check()
     time.sleep(5)
     s.SendMessageForFeiqTCP()
     time.sleep(5)
     t.TelnetTestFile()
     time.sleep(5)
     app.e3check()
     time.sleep(5)
     if ipaddr == '10.95.27.116':
         app.e4()
         time.sleep(5)
     https.httpsSLL()
     time.sleep(5)
     app.e6()
     time.sleep(5)
     '''
     app.h6check()
     time.sleep(5)
     app.h6check()#因为测试过程中发现第一次没有执行,所以再重新执行一次,这里不是手误写错了
     time.sleep(5)
     app.n1check()
     time.sleep(5)
     app.n2check()
     time.sleep(5)
     app.n3check()
     time.sleep(5)
     app.n4check()
     time.sleep(5)
     app.n5check()
     time.sleep(5)
     app.n6check()
     time.sleep(5)
     app.n7check()
     time.sleep(5)
     app.o1check()
     time.sleep(5)
     '''
     app.netallcheck()
     time.sleep(30)
     app.OutputFileCheck()
     time.sleep(5)
     app.w1check()
     time.sleep(5)
     app.w2check()
     time.sleep(5)
     app.w3check()
     time.sleep(5)
     c.window_capture()
     time.sleep(5)