Skip to content

Instantly share code, notes, and snippets.

@marria05
Last active May 18, 2022 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marria05/da183d4aae38c43327e11a75f8eab11c to your computer and use it in GitHub Desktop.
Save marria05/da183d4aae38c43327e11a75f8eab11c to your computer and use it in GitHub Desktop.
Create a Mikrotik address list from the AWS 'ip-ranges' API
#!/usr/bin/python3
# -*- coding: iso-8859-1 -*-
# Launch with AWS region name as the only command line argument ie. ./mikrotik_aws_addresslists.py eu-west-1
# A list of addresses, along with requisite terminal commands prepended to each line is spewed forth from stdout,
# which can be redirected to a file.
import signal
import json
import requests
import sys
#==================================================================================================================
def interruptHandler(signum, frame):
exit()
return
def main():
response = requests.Session().get("https://ip-ranges.amazonaws.com/ip-ranges.json")
if response.status_code != 200:
return
print(str.join('\n', ['/ip firewall address-list add list=' + sys.argv[1] + ' address=' + row['ip_prefix'] for row in response.json()['prefixes'] if row['region'] == sys.argv[1]]))
return
#==================================================================================================================
if __name__ == "__main__":
signal.signal(signal.SIGINT, interruptHandler)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment