Created
March 29, 2022 01:20
-
-
Save sam210723/9116fcb3309bb304e63d3235fd13f272 to your computer and use it in GitHub Desktop.
Check the status of your ADS-B Exchange feeder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
adsbx-feeder-connection.py | |
Check the status of your ADS-B Exchange feeder | |
""" | |
import sys | |
import urllib.request | |
json_output = "json" in sys.argv | |
# Get status from ADS-B Exchange server | |
request = urllib.request.urlopen( | |
urllib.request.Request( | |
'http://www.adsbexchange.com/myip', | |
data=None, | |
headers={ | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36' | |
} | |
) | |
) | |
contents = request.read().decode('utf-8') | |
request.close() | |
# Get public IP address | |
contents = contents[contents.find('Your Web Browser IP<br />') + 34 :] | |
ip = contents[: contents.find('</strong>')] | |
# Get ADS-B status | |
contents = contents[contents.find('<div class="center"><img width="50px" src="./images/') + 52 :] | |
adsb = True if contents[: contents.find('.png')] == "green" else False | |
# Get MLAT status | |
contents = contents[contents.find('<div class="center"><img width="50px" src="./images/') + 52 :] | |
mlat = True if contents[: contents.find('.png')] == "green" else False | |
# Write status to console in requested format | |
if json_output: | |
import json | |
print(json.dumps({'ip': ip, 'adsb': adsb, 'mlat': mlat})) | |
else: | |
print(f'IP: {ip} ADS-B: {"OK" if adsb else "ERROR"} MLAT: {"OK" if mlat else "ERROR"}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment