Esempio n. 1
0
def addClient(device_ip_address, port, device_login, device_password, login_client, password_client,
        ip_client, ipv6_client, speed_up, speed_up_unity, speed_down, speed_down_unity):
    mikrotik = Core(device_ip_address, port=port)
    mikrotik.login(device_login, device_password)
    mikrotik.response_handler(mikrotik.talk(["/ppp/secret/add", "=name=" + login_client, "=password="******"=local-address=" + device_ip_address, "=remote-address=" + ip_client,
        "=profile=" + str(speed_up)+speed_up_unity+str(speed_down)+speed_down_unity]))
    mikrotik.response_handler(mikrotik.talk(["/ip/firewall/address-list/add", "=address=" + ip_client, "=list=" + "internet",]))
Esempio n. 2
0
def clientOff(device_ip_address, port, device_login, device_password, ip_client):
    mikrotik = Core(device_ip_address, port=port)
    mikrotik.login(device_login, device_password)
    for rule in ret_data(mikrotik.response_handler(mikrotik.talk(["/ip/firewall/address-list/print", "=.proplist="+".id,address",]))):
        try:
            if rule["address"] == ip_client:
                mikrotik.response_handler(mikrotik.talk(["/ip/firewall/address-list/disable", "=.id=" + rule[".id"],]))
        except:
            pass
Esempio n. 3
0
def deleteAddressList(device_ip_address, port, device_login, device_password, ip_client):
    mikrotik = Core(device_ip_address, port=port)
    mikrotik.login(device_login, device_password)
    for rule in ret_data(mikrotik.response_handler(mikrotik.talk(["/ip/firewall/address-list/print", "=.proplist="+".id,address",]))):
        try:
            if rule["address"] == ip_client:
                mikrotik.response_handler(mikrotik.talk(["/ip/firewall/address-list/remove", "=.id=" + rule[".id"],]))
        except:
            pass
Esempio n. 4
0
def deletePPP(device_ip_address, port, device_login, device_password, ip_client):
    mikrotik = Core(device_ip_address, port=port)
    mikrotik.login(device_login, device_password)
    for rule in ret_data(mikrotik.response_handler(mikrotik.talk(["/ppp/secret/print", "=.proplist="+".id,remote-address",]))):
        try:
            if rule["remote-address"] == ip_client:
                mikrotik.response_handler(mikrotik.talk(["/ppp/secret/remove", "=.id=" + rule[".id"],]))
        except:
            pass
def updatePPPIP(device_ip_address, port, device_login, device_password, ip_client_old, ip_client_new):
    mikrotik = Core(device_ip_address, port=port)
    mikrotik.login(device_login, device_password)
    for rule in ret_data(mikrotik.response_handler(mikrotik.talk(["/ppp/secret/print", "=.proplist="+".id,remote-address",]))):
        try:
            if rule["remote-address"] == ip_client_old:
                print "Update IP" + rule[".id"]
                mikrotik.response_handler(mikrotik.talk(["/ppp/secret/set", "=remote-address=" + ip_client_new, "=.id=" + rule[".id"],]))
        except:
            pass
def updateLogin(device_ip_address, port, device_login, device_password, login_client_old, login_client_new):
    mikrotik = Core(device_ip_address, port=port)
    mikrotik.login(device_login, device_password)
    for rule in ret_data(mikrotik.response_handler(mikrotik.talk(["/ppp/secret/print", "=.proplist="+".id,name",]))):
        try:
            if rule["name"] == login_client_old:
                print "Update login" + rule[".id"]
                mikrotik.response_handler(mikrotik.talk(["/ppp/secret/set", "=name=" + login_client_new, "=.id=" + rule[".id"],]))
        except:
            pass
Esempio n. 7
0
def createTarifAddQueue(device_ip_address, port, device_login, device_password,
                        speed_up, speed_up_unity, speed_down,
                        speed_down_unity):
    mikrotik = Core(device_ip_address, port=port)
    mikrotik.login(device_login, device_password)
    mikrotik.response_handler(
        mikrotik.talk([
            "/ppp/profile/add",
            "=name=" + str(speed_up) + speed_up_unity + str(speed_down) +
            speed_down_unity,
            "=rate-limit=" + str(speed_up) + speed_up_unity + "/" +
            str(speed_down) + speed_down_unity,
        ]))
Esempio n. 8
0
def deleteTarifAndQueue(device_ip_address, port, device_login, device_password,
                        speed_up, speed_up_unity, speed_down,
                        speed_down_unity):
    mikrotik = Core(device_ip_address, port=port)
    mikrotik.login(device_login, device_password)
    for rule in ret_data(
            mikrotik.response_handler(
                mikrotik.talk([
                    "/ppp/profile/print",
                    "=.proplist=" + ".id,rate-limit",
                ]))):
        try:
            if rule["rate-limit"] == str(
                    speed_up) + speed_up_unity + "/" + str(
                        speed_down) + speed_down_unity:
                mikrotik.response_handler(
                    mikrotik.talk([
                        "/ppp/profile/remove",
                        "=.id=" + rule[".id"],
                    ]))
                print rule[".id"]
        except:
            pass
Esempio n. 9
0
def getPPP(device_ip_address, port, device_login, device_password, ip_client):
    mikrotik = Core(device_ip_address, port=port)
    mikrotik.login(device_login, device_password)
    for rule in ret_data(
            mikrotik.response_handler(
                mikrotik.talk([
                    "/ppp/active/print",
                    "=.proplist=" + ".id,address",
                ]))):
        try:
            if rule["address"] == ip_client:
                return True
        except:
            pass