Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib
- import matplotlib.patches as mpatches
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- import matplotlib.ticker as plticker
- USERNAME = 'ubnt'
- PASSWORD = 'ubnt1'
- HOST = "192.168.1.220"
- PORT = 18888
- TIMEOUT = 10
- FRAME_SPEED = 1
- LOGIN_URI = 'http://' + HOST + ':80/login.cgi'
- #LOGIN_URI = 'https://' + HOST + ':443/login.cgi'
- def usage():
- print ("Usage:+ sys.argv[0] + <live|replay FILENAME>")
- print ("")
- print ("Options:")
- print ("tlive t=tProcess live data from device ") + HOST
- print ("treplay FILENAME t=tReplay FILENAME")
- print ("trecord FILENAME t=tMake movie of FILENAME")
- exit(128)
- if len(sys.argv) == 2 and sys.argv[1] == 'live':
- ACTION='live'
- FILENAME = None
- elif len(sys.argv) == 3 and sys.argv[1] == 'replay':
- ACTION='replay'
- ocessing
- FRAME_SPEED = 50
- elif len(sys.argv) == 3 and sys.argv[1] == 'record':
- ACTION='record'
- FILENAME = sys.argv[2] # Stored data processing
- FRAME_SPEED = 50
- else:
- usage()
- def parse_get_frame_resp(line):
- _,vals_raw = line.split(':')
- vals = map(int, vals_raw.split(','))
- frame_nr = vals.pop(0)
- return(frame_nr, vals)
- #TODO: Make me dynamic parse from 'SCAN RANGE' response
- scan_range_begin = 2402000000
- scan_range_end = 2497000000
- if not FILENAME:
- print ("Enabling Ubiquiti airView at %s:%s@%s...") %(USERNAME, PASSWORD, HOST)
- s = requests.session()
- s.get(LOGIN_URI, verify=False)
- r = s.post(LOGIN_URI,
- {"username": USERNAME, "password": PASSWORD, "uri": "airview.cgi? start=1"},
- verify=False)
- if 'Invalid credentials.' in r.text:
- print ("# CRIT: Username/password invalid!")
- sys.exit(1)
- print ("Waiting for device to enter airView modus...")
- # Allow device a few moments to settle
- time.sleep(TIMEOUT)
- print ("Start scanning...")
- tn = telnetlib.Telnet(HOST, PORT, timeout=TIMEOUT)
- #tn.set_debuglevel(99)
- # Storage on unique files
- outfile = 'output-%s.dat' % int(time.time())
- print ("Storing output at '%s'") % outfile
- fh = open(outfile, 'a')
- def writeline(cmd):
- """ Write line to device"""
- ts = time.time()
- tn.write(cmd)
- print (cmd)
- fh.write("%s 01%s" % (ts, cmd))
- return ts
- def getline():
- """Read line from device"""
- line = tn.read_until("n")
- print (line)
- fh.write("%s 01%s" % (time.time(), line))
- return line
- # Commands needs to have a trailing space if no arguments specified
- writeline("CONNECT: n")
- getline()
- #writeline("REQUEST RANGE: 2402000000,2407000000n") # 5 MHz
- #writeline("REQUEST RANGE: 2402000000,2412000000n") # 10 MHz
- #writeline("REQUEST RANGE: 2402000000,2417000000n") # 15 MHz
- #writeline("REQUEST RANGE: 2402000000,2422000000n") # 20 Mhz
- #writeline("REQUEST RANGE: 2402000000,2477000000n") # (ch 1-11 - US allocation)
- #writeline("REQUEST RANGE: 2402000000,2487000000n") # (ch 1-13 - UK allocation)
- writeline("REQUEST RANGE: 2402000000,2497000000n") # (ch 1-14)
- getline()
- writeline("START SCAN: n")
- getline()
- print ("Waiting for scan to start...")
- time.sleep(2)
- def get_frame(frame):
- """ Get frame from device airView """
- # TODO: Receiving frames in order, sometimes yield of empty responses. Already flush out maybe?
- #writeline("GET FRAME: %sn" % frame)
- ts = writeline("GET FRAME: n")
- line = getline()
- return((ts,) + parse_get_frame_resp(line))
- else:
- # No need for logic since we are processing stored data
- sh = open(FILENAME, 'r')
- def get_frame(frame):
- """ Perform replay data processing """
- while True:
- line = sh.readline()
- if not line:
- return(None, None, None)
- ts_raw, a = line.split('