Hospot Active user Disconnect Script Issue

Hi all,

I need you help :slight_smile:
I have 2x Mikrotik routers running the hotspot server one will be active at a time while the other is for backup.
I also have 2x Mikrotik routers running as Radius servers, one will be active while the other is for backup.

My script used to work fine for a long time, it will sucessfully disconnect the active hotspot user from the hotspot server and after a while the user
will get auto-disconnected also from the active Radius server. This is no longer happening when I run my script now only the active hotspot user will be disconnected while the user will stay connected on the Radius server.

If I do this process manually by disconnecting the active hotspot user from the server through Winbox both the active user will be disconnected from the running hotspot server and also from the running Radius server.

Can you please double check my script and see what changes need to be made.

Many Thanks in advance for all your help.

Oh the script is run with Python 2.7.18


#!/usr/bin/python
import getpass
import sys
import telnetlib
import time
import datetime
from datetime import date
from datetime import time
from datetime import datetime

account = raw_input("Enter code to reset: ")
host = "router1"
host2 = "router2"
password = "routerpassword"

Open Telnet Connetions to host

tn = telnetlib.Telnet(host)

Perform login

a = tn.read_until("Login:",5)
tn.write("admin+tce80w24h\r")
a = tn.read_until("Password:",5)
tn.write(password+"\r")
a = tn.read_until(">",3)

Remove User from Active

tn.write('/ip hotspot active remove [find user="'+account+'"]\r')#

done

a = tn.read_until(">",5)
tn.write("/quit\r")

Get any data left in buffer

a = tn.read_all()

Open Telnet Connetions to host2

tn = telnetlib.Telnet(host2)

Perform login

a = tn.read_until("Login:",5)
tn.write("admin+tce80w24h\r")
a = tn.read_until("Password:",5)
tn.write(password+"\r")
a = tn.read_until(">",3)

Remove User from Active

tn.write('/ip hotspot active remove [find user="'+account+'"]\r')#

done

a = tn.read_until(">",5)
tn.write("/quit\r")

Get any data left in buffer

a = tn.read_all()

f= open("c:\mikrotik\wifi.log","a+")
dt=datetime.now()
f.write(str(dt))
f.write("\r\n")
f.write(getpass.getuser())
f.write(" - ")
f.write(account)
f.write(" Disconnected\r\n")

f.close()

exit ()