Exemple #1
0
def readvlan():
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    print(vyos.run_op_mode_command("show ip route"))
    y = vyos.run_op_mode_command("show ip route")
    vyos.logout()
    return y
Exemple #2
0
def deldns(name):
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.delete("service dns forwarding name-server %s" % (name))
    vyos.commit()
    vyos.save()
Exemple #3
0
def del_bridge(bridge):
    vyos = vymgmt.Router('13.231.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.delete("int bridge %s" % (bridge))
    vyos.commit()
    vyos.save()
    vyos.exit()
Exemple #4
0
def del_vlan(ethernet, vlan):
    vyos = vymgmt.Router('13.231.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.delete("int eth %s vif %s" % (ethernet, vlan))
    vyos.commit()
    vyos.save()
    vyos.exit()
Exemple #5
0
def readuser():
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.run_op_mode_command("show system login users")
    vyos.commit()
    vyos.save()
    vyos.exit()
    vyos.logout()
Exemple #6
0
def deleteuser(name):
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.delete("system login user %a" % (name))
    vyos.commit()
    vyos.save()
    vyos.exit()
    vyos.logout()
Exemple #7
0
def set_vlan(ethernet, vlan, desc, ip):
    vyos = vymgmt.Router('13.231.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.set("int eth %s vif %s desc %s " % (ethernet, vlan, desc))
    vyos.set("int eth %s vif %s address %s" % (ethernet, vlan, ip))
    vyos.commit()
    vyos.save()
    vyos.exit()
Exemple #8
0
def createdns(name, eth):
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.set("service dns forwarding name-server %s" % (name))
    vyos.set("service dns forwarding  listen-on %s" % (eth))
    vyos.commit()
    vyos.save()
    vyos.exit()
Exemple #9
0
def readdhcp():
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    print(vyos.run_conf_mode_command("show service dhcp"))
    x = vyos.run_conf_mode_command("show service dhcp")
    vyos.exit()
    vyos.logout()
    return x
Exemple #10
0
def deletevlan( interface, number):
	vyos = vymgmt.Router('192.168.0.1','vyos', password='******', port=22)
	vyos.login()
	vyos.configure()
	vyos.delete("interfaces ethernet %b vif %b" %(interface, number))
	vyos.commit()
	vyos.save()
	vyos.exit()
	vyos.logout()
Exemple #11
0
def delfirewall(fname):
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.delete("firewall name %s default-action 'reject'" % fname)
    vyos.commit()
    vyos.save()
    vyos.exit()
    vyos.logout()
Exemple #12
0
def sendping(ip, user, ps, vpnip):
    c1 = 'sudo killall -9 ping'
    cmd = 'sudo ping -c30 ' + vpnip + ' > /dev/null 2>&1 &'
    handle = vymgmt.Router(ip, user, password=ps, port=22)
    handle.login()
    handle.run_op_mode_command(c1)
    out = handle.run_op_mode_command(cmd)
    handle.exit()
    handle.logout()
Exemple #13
0
def capture_traffic(ip, user, ps, iface):
    cmd = 'sudo timeout 5 tcpdump -i ' + iface
    handle = vymgmt.Router(ip, user, password=ps, port=22)
    handle.login()
    out = handle.run_op_mode_command(cmd)
    handle.exit()
    handle.logout()
    output = out.split("\n")
    return output
Exemple #14
0
def readfirewall():
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    print(vyos.run_conf_mode_command("show firewall name"))
    y = vyos.run_conf_mode_command("show firewall name")
    vyos.exit()
    vyos.logout()
    return y
Exemple #15
0
def show_command(ip, user, ps, cmd):
    handle = vymgmt.Router(ip, user, password=ps, port=22)
    handle.login()
    out = handle.run_op_mode_command(cmd)
    handle.exit()
    handle.logout()
    output = out.split("\n")
    #output2 = ''.join([str(elem) for elem in output])
    return output
Exemple #16
0
def createdhcp(type):
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.set("service dhcp-server shared-network-name 'LAN' authoritative %s" %
             (type))
    vyos.commit()
    vyos.save()
    vyos.exit()
Exemple #17
0
def readdns():
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    print(vyos.run_op_mode_command("show dns forwarding nameservers"))
    y = vyos.run_op_mode_command("show dns forwarding nameservers")
    vyos.exit()
    vyos.logout()
    return y
Exemple #18
0
def config_set(ip, user, ps, cmd):
    handle = vymgmt.Router(ip, user, password=ps, port=22)
    handle.login()
    handle.configure()
    handle.set(cmd)
    handle.commit()
    handle.save()
    handle.exit()
    handle.logout()
Exemple #19
0
def delvlan(eth, num):
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.delete("interfaces ethernet %s vif '%s' " % (eth, num))
    vyos.commit()
    vyos.save()
    vyos.exit()
    vyos.logout()
Exemple #20
0
def config_show(ip, user, ps, cmd):
    handle = vymgmt.Router(ip, user, password=ps, port=22)
    handle.login()
    handle.configure()
    out = handle.run_conf_mode_command(cmd)
    handle.exit()
    handle.logout()
    output = out.split("\n")
    return output
Exemple #21
0
def createfirewall(fname):
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.set("firewall name %s default-action 'accept'" % fname)
    vyos.commit()
    vyos.save()
    vyos.exit()
    vyos.logout()
Exemple #22
0
def createvlan(interface, number, description, address):
	vyos = vymgmt.Router('192.168.0.1','vyos', password='******', port=22)
	vyos.login()
	vyos.configure()
	vyos.set("interfaces ethernet %b vif %b description %b" %(interface, number, description))
	vyos.set("interfaces ethernet %b vif %b address %b" %(interface, number, address))
	vyos.commit()
	vyos.save()
	vyos.exit()
	vyos.logout()
Exemple #23
0
def apply_rule(ip, user, ps, iface, rule, cmd):
    command = cmd.replace('INTERFACE', iface).replace('RULE', rule)
    handle = vymgmt.Router(ip, user, password=ps, port=22)
    handle.login()
    handle.configure()
    handle.set(command)
    handle.commit()
    handle.save()
    handle.exit()
    handle.logout()
Exemple #24
0
def config_show_service(ip, user, ps, cmd):
    handle = vymgmt.Router(ip, user, password=ps, port=22)
    handle.login()
    handle.configure()
    out = handle.run_conf_mode_command(cmd)
    handle.exit()
    handle.logout()
    output = out.split("\n")
    output2 = ''.join([str(elem) for elem in output])
    return output2
Exemple #25
0
def set_bridge(bridge, ethernet, ip):
    vyos = vymgmt.Router('13.231.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.set("int bridge %s" % (bridge))
    vyos.set("int bridge %s address %s" % (bridge, ip))
    vyos.set("int bridge %s stp true" % (bridge))
    vyos.commit()
    vyos.save()
    vyos.exit()
Exemple #26
0
def createvlan(eth, num, desc, ip):
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.set("interfaces ethernet %s vif %s description '%s'" %
             (eth, num, desc))
    vyos.set("interfaces ethernet %s vif %s address %s" % (eth, num, ip))
    vyos.commit()
    vyos.save()
    vyos.exit()
    vyos.logout()
Exemple #27
0
def config(ip, user, ps, cmd):
    handle = vymgmt.Router(ip, user, password=ps, port=22)
    handle.login()
    handle.configure()
    for line in cmd:
        print(line)
        handle.set(line)
    handle.commit()
    handle.save()
    handle.exit()
    handle.logout()
Exemple #28
0
def clear(vy_host):
    console = vymgmt.Router(vy_host, "vyos", "vyos", 22)
    console.login()
    out = console.run_op_mode_command(
        "sudo rm /opt/vyatta/etc/config/ipsec.d/rsa-keys/localhost.key /config/ipsec.d/rsa-keys/localhost.key"
    )
    console.configure()
    console.run_conf_mode_command("load /config/clear.config")
    out = console.run_conf_mode_command("commit")
    console.exit(force=True)
    console.logout()
    assert "Traceback" not in out
Exemple #29
0
def connect(address, username, password, port):
    '''
    Provide a connection to the box
    address(string)
    username(string)
    password(string)
    port(int)

    Return: connection object
    '''
    vyos = vymgmt.Router(address, username, password=password, port=port)
    return(vyos)
Exemple #30
0
def createuser(name, fullname, userlevel, password):
    vyos = vymgmt.Router('192.168.0.1', 'vyos', password='******', port=22)
    vyos.login()
    vyos.configure()
    vyos.set("system login user %a fullname %a" % (name, fullname))
    vyos.set("system login user %a authentication plaintext-password %a" %
             (name, password))
    vyos.set("system login user %a level %a" % (name, userlevel))
    vyos.commit()
    vyos.save()
    vyos.exit()
    vyos.logout()