-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_github_hosts.py
More file actions
25 lines (20 loc) · 885 Bytes
/
Copy pathadd_github_hosts.py
File metadata and controls
25 lines (20 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import base64
import subprocess
ps_script = """
$hostsPath = 'C:\\Windows\\System32\\drivers\\etc\\hosts'
$entry = '140.82.113.3 github.com api.github.com codeload.github.com'
$content = Get-Content $hostsPath -Raw
if ($content -notlike '*140.82.113.3 github.com*') {
Add-Content -Path $hostsPath -Value "`n# Direct GitHub IPv4 Route Fix`n$entry"
}
ipconfig /flushdns
"""
encoded = base64.b64encode(ps_script.encode('utf-16le')).decode('ascii')
cmd = f"powershell -Command \"Start-Process powershell -ArgumentList '-EncodedCommand {encoded}' -Verb RunAs -Wait\""
subprocess.run(cmd, shell=True, capture_output=True)
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
print("--- Testing git push / connection to github.com ---")
res = subprocess.run("git push", shell=True, capture_output=True, text=True, cwd=str(ROOT))
print(res.stdout)
print(res.stderr)