Skip to content

Instantly share code, notes, and snippets.

@jizhang
Created June 11, 2015 15:05
Show Gist options
  • Save jizhang/335c91770c8d65245a67 to your computer and use it in GitHub Desktop.
Save jizhang/335c91770c8d65245a67 to your computer and use it in GitHub Desktop.
Add Route in Windows
import re
import subprocess
ipconfig = subprocess.check_output(['ipconfig'])
mo = re.search(r'192\.168\.189\.[0-9]+', ipconfig)
vpn = mo.group()
ips = [
['192.168.1.100'],
['192.168.1.61'],
['192.168.1.95'],
['192.168.1.93'],
['192.168.1.70'],
['192.168.1.86'],
['192.168.1.24'],
['10.0.0.0', '255.0.0.0']
]
for ip in ips:
if len(ip) == 1:
subprocess.check_call(['route', 'add', ip[0], vpn])
else:
subprocess.check_call(['route', 'add', ip[0], 'mask', ip[1], vpn])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment