Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #by Bino Oetomo
- #save it to mtwlstat.py
- #call it --> python mtwlstat a:b@host:port, where
- #++ a = your API user name
- #++ b = your API passwword
- #++ host = your mikrotik AP address
- #++ port = your mikrotik AP API port
- #REQUIRE = librouteros ( https://pypi.python.org/pypi/librouteros/ )
- import time
- from librouteros import connect
- import re
- class wlstat():
- def __init__(self, inCred):
- incred, inhost = inCred.strip().split('@')
- self.user, self.password = incred.strip().split(':')
- self.user = self.user.strip()
- self.password = self.password.strip()
- self.host = inhost.strip().split(':')[0].strip()
- try :
- self.port = inhost.strip().split(':')[1].strip()
- except :
- self.port = '8728'
- def poll(self) :
- ts = int(time.time())
- api = connect(host=self.host, port=self.port, username=self.user, password=self.password)
- cmd = '/ip/neighbor/print'
- results = api(cmd=cmd)
- neighbors = {}
- cmd = '/interface/wireless/registration-table/print'
- results = api(cmd=cmd)
- clients = []
- for r in results :
- thisClient={}
- thisClient['clientMAC'] = r['mac-address']
- thisClient['clientName'] = r['radio-name']
- thisClient['clientSignal'] = int(r['signal-strength'].split('@')[0])
- thisClient['clientNoise'] = thisClient['clientSignal'] - r['signal-to-noise']
- thisClient['clientDistance'] = r['distance']
- thisClient['clientTxCCQ'] = r['tx-ccq']
- thisClient['clientRxCCQ'] = r['rx-ccq']
- thisClient['pollTS'] = ts
- try :
- thisClient['clientIP'] = neighbors[str(thisClient['clientMAC'])]
- except :
- thisClient['clientIP'] = 'unknown'
- clients.append(thisClient)
- return clients
- if __name__ == "__main__":
- import sys
- inTarget = sys.argv[1].strip()
- try :
- inSleep = int(sys.argv[2].strip())
- except :
- inSleep = 10
- poller = wlstat(inTarget)
- while True :
- for d in poller.poll() :
- print d
- time.sleep(inSleep)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement