Last active
April 7, 2022 18:52
-
-
Save samicrusader/97fcaa44f57fd6d4d22c5adb43867939 to your computer and use it in GitHub Desktop.
webtv server routes script
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 os | |
import subprocess | |
## Change me! | |
ServerIP = '74.76.120.18' # MattMan | |
#ServerIP = '51.222.164.146' # Zefie | |
DNSServer = '9.9.9.9' # quad9.net | |
#DNSServer = '1.1.1.1' # cloudflare-dns.com | |
#DNSServer = '8.8.8.8' # dns.google | |
#DNSServer = '208.67.222.222' # use.opendns.com | |
## Don't change me! | |
tmppath = '/tmp/routes.txt' | |
ipranges = [ | |
'10.0.0.1', # US Production | |
'10.0.0.2', | |
'10.0.1.1', | |
'10.0.1.2', | |
'10.0.1.3', | |
'10.0.1.4', | |
'10.0.128.1', # US Daily | |
'10.0.1.129', # Japanese Dreamcast | |
'10.0.128.2', | |
'10.0.129.1', | |
'10.0.129.2', | |
'10.0.130.1', | |
'10.0.130.2', | |
'10.0.131.1', | |
'10.0.131.2', | |
'10.0.132.1', | |
'10.0.132.2', | |
'209.240.192.0/19', # US WebTV IP address range | |
'204.254.74.126', # listed on ConnectSetup page | |
'210.150.22.37', # JP WebTV Service | |
'210.150.22.58', # JP WebTV Service | |
] | |
for ip in ipranges: | |
if os.path.isfile(tmppath): # this file existing means we already set routes | |
oldip = open(tmppath, 'r').read().strip() | |
# purge old routes without clearing all rules | |
try: | |
subprocess.check_output(['iptables', '-t', 'nat', '-D', 'PREROUTING', '-d', ip, '-j', 'DNAT', '--to-destination', oldip]) | |
except Exception as e: | |
pass | |
try: | |
oip = ip | |
if oip == '209.240.192.0/19': | |
oip = '209.240.192.0-209.240.223.255' | |
x = subprocess.check_output(['iptables', '-t', 'nat', '-D', 'POSTROUTING', '-d', oldip, '-j', 'SNAT', '--to-source', oip]) | |
except Exception as e: | |
pass | |
# add routes | |
oldip = open(tmppath, 'w').write(ServerIP) | |
subprocess.check_output(['iptables', '-t', 'nat', '-A', 'PREROUTING', '-d', ip, '-j', 'DNAT', '--to-destination', ServerIP]) | |
if ip == '209.240.192.0/19': ip = '209.240.192.0-209.240.223.255' | |
subprocess.check_output(['iptables', '-t', 'nat', '-A', 'POSTROUTING', '-d', ServerIP, '-j', 'SNAT', '--to-source', ip]) | |
# special route for DNS server | |
subprocess.check_output(['iptables', '-t', 'nat', '-A', 'PREROUTING', '-d', '157.57.221.51', '-j', 'DNAT', '--to-destination', DNSServer]) | |
subprocess.check_output(['iptables', '-t', 'nat', '-A', 'POSTROUTING', '-d', DNSServer, '-j', 'SNAT', '--to-source', '157.57.221.51']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment