Skip to content

Instantly share code, notes, and snippets.

@vampjaz
Last active April 6, 2019 17:40
Show Gist options
  • Save vampjaz/19e49f1158583022db3d to your computer and use it in GitHub Desktop.
Save vampjaz/19e49f1158583022db3d to your computer and use it in GitHub Desktop.
FlightRadar24 local streaming API parser
## test file to decode data from FlightRadar24 streaming server
## see http://redteamgreen.blogspot.com/2015/12/big-data-is-sometimes-big-pain.html
import socket
import sys, os
import time
def pad(s,l):
return ' '*(l-len(s)) + s
class plane:
def __init__(self,pid,flight=None,alt=None,lat=None,lon=None,heading=None,speed=None):
self.plane = pid
self.flight = flight
self.alt = alt
self.lat = lat
self.lon = lon
self.dir = heading
self.speed = speed
self.lastupdate = time.time()
self.pps = 0
def update(self,flight=None,alt=None,lat=None,lon=None,heading=None,speed=None):
if flight and flight != self.flight:
self.flight = flight
if alt and alt != self.alt:
self.alt = alt
if lon and lon != self.lon:
self.lon = lon
if lat and lat != self.lat:
self.lat = lat
if heading and heading != self.dir:
self.dir = heading
if speed and speed != self.speed:
self.speed = speed
self.lastupdate = time.time()
self.pps += 1
def show(self):
print "{}: {} {}ft {}mph {}E {}N {}deg {}sec {}".format(self.plane,pad(self.flight,10),pad(self.alt,10),pad(self.speed,10),pad(self.lat,15),pad(self.lon,15),pad(self.dir,10),pad(str(int(time.time() - self.lastupdate)),10),pad(str(self.pps),5))
self.pps = 0
planes = {}
def updateplanes():
global planes
now = time.time()
for i in planes.keys():
if planes[i].lastupdate + 60 < now:
del planes[i]
def process(msg):
global planes
try:
msg = msg.strip().split(',')
if msg[0] == 'MSG':
pid = msg[4]
flight = msg[10]
alt = msg[11]
lat = msg[15]
lon = msg[14]
heading = msg[13]
speed = msg[12]
if not pid in planes.keys():
planes[pid] = plane(pid,flight=flight,alt=alt,lat=lat,lon=lon,heading=heading,speed=speed)
return True
else:
planes[pid].update(flight=flight,alt=alt,lat=lat,lon=lon,heading=heading,speed=speed)
return False
except KeyboardInterrupt:
sys.exit(0)
except:
pass
def scan(ip):
s = socket.create_connection((ip,30003))
buff = ''
last = time.time()
pkts = 0
byts = 0
tplanes = 0
while True:
read = s.recv(512)
byts += len(read)
buff += read
t = buff.split('\n',1)
if len(t) > 1:
if process(t[0]):
tplanes += 1
pkts += 1
#print t[0]
buff = t[1]
updateplanes()
now = time.time()
if last + 1 < now:
last = now
#os.system('clear') ## not very portable, so:
sys.stderr.write("\x1b[2J\x1b[H")
# A34B51: N311JA 41025ft 230mph -116.72150E 47.52183N 90.3deg 0sec Last seen
print "ID: Flight Alt Speed Lat Lon Heading Last seen PPS"
for i in planes.keys():
planes[i].show()
print
print "Bytes/sec: {} \t Packets/sec: {} \t Avg bytes/pkt: {}".format(byts,pkts,byts/pkts)
print "Planes visible: {} \t Total seen: {}".format(len(planes),tplanes)
byts = 0
pkts = 0
if __name__ == "__main__":
scan(sys.argv[1])
@vampjaz
Copy link
Author

vampjaz commented Dec 25, 2015

Simply run it with: python fr24_feed.py <local ip of your FlightRadar decoder box>

You should be able to figure this out from the online feed manager:

You can also see your feeder statistics in Premium. Select "Your Feeds"
and then "More Info". Here is an example:

http://goo.gl/SrZ6sk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment