Last active
September 29, 2023 19:39
-
-
Save m13253/d3abd8be6ff8b0898235643a4308ea7e to your computer and use it in GitHub Desktop.
Generate MikroTik address list with IP addresses of CS:GO official matchmaking servers
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
#!/usr/bin/env python3 | |
import json | |
import netaddr | |
def main(): | |
# Download from https://api.steampowered.com/ISteamApps/GetSDRConfig/v1?appid=730 | |
with open('network_config.json', 'r', encoding='utf-8') as f: | |
network_config = json.load(f) | |
pops = dict.get(network_config, 'pops') | |
results = [] | |
for k, v in dict.items(pops): | |
desc = dict.get(v, 'desc') | |
name = k + ' - ' + desc if desc else k | |
addresses = [] | |
for relay in dict.get(v, 'relays', []): | |
address = dict.get(relay, 'ipv4') | |
addresses.append(netaddr.IPAddress(address)) | |
addresses = netaddr.cidr_merge(addresses) | |
addresses.sort() | |
results.append((name, addresses)) | |
results.sort() | |
print('/ip firewall address-list') | |
print('remove [ find list=csgo ]') | |
for name, addresses in results: | |
for address in addresses: | |
print('add address={} comment="CS:GO {}" list=csgo'.format(address, name)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment