Show external IP before and after Mullvad activation
This commit is contained in:
parent
2780a846bf
commit
c90068c6f3
1 changed files with 25 additions and 5 deletions
|
|
@ -11,6 +11,7 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
def _run_tailscale(args, timeout=30):
|
def _run_tailscale(args, timeout=30):
|
||||||
|
|
@ -118,6 +119,20 @@ def show_status():
|
||||||
print("Mullvad: OFF")
|
print("Mullvad: OFF")
|
||||||
|
|
||||||
|
|
||||||
|
def get_external_ip():
|
||||||
|
"""Get the current external IP address."""
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
["curl", "-s", "--connect-timeout", "5", "https://api.ipify.org"],
|
||||||
|
capture_output=True, text=True, timeout=10,
|
||||||
|
)
|
||||||
|
if result.returncode == 0 and result.stdout.strip():
|
||||||
|
return result.stdout.strip()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return "Unknown"
|
||||||
|
|
||||||
|
|
||||||
def cmd_on(location):
|
def cmd_on(location):
|
||||||
"""Connect to a Mullvad exit node matching the given location."""
|
"""Connect to a Mullvad exit node matching the given location."""
|
||||||
nodes = get_exit_nodes()
|
nodes = get_exit_nodes()
|
||||||
|
|
@ -139,6 +154,8 @@ def cmd_on(location):
|
||||||
node = random.choice(matches)
|
node = random.choice(matches)
|
||||||
hostname = node["hostname"]
|
hostname = node["hostname"]
|
||||||
|
|
||||||
|
ip_before = get_external_ip()
|
||||||
|
print(f"Current IP: {ip_before}")
|
||||||
print(f"Connecting to Mullvad: {node['country']} - {node['city']} ({hostname})")
|
print(f"Connecting to Mullvad: {node['country']} - {node['city']} ({hostname})")
|
||||||
print("Tearing down Tailscale...")
|
print("Tearing down Tailscale...")
|
||||||
_run_tailscale_live(["down", "--accept-risk=lose-ssh"])
|
_run_tailscale_live(["down", "--accept-risk=lose-ssh"])
|
||||||
|
|
@ -146,7 +163,10 @@ def cmd_on(location):
|
||||||
_run_tailscale_live(
|
_run_tailscale_live(
|
||||||
["up", "--reset", "--accept-risk=lose-ssh", f"--exit-node={hostname}", "--exit-node-allow-lan-access=false", "--accept-routes"]
|
["up", "--reset", "--accept-risk=lose-ssh", f"--exit-node={hostname}", "--exit-node-allow-lan-access=false", "--accept-routes"]
|
||||||
)
|
)
|
||||||
|
time.sleep(1)
|
||||||
|
ip_after = get_external_ip()
|
||||||
print(f"Mullvad: ON -> {hostname} ({node['country']}, {node['city']})")
|
print(f"Mullvad: ON -> {hostname} ({node['country']}, {node['city']})")
|
||||||
|
print(f"IP: {ip_before} -> {ip_after}")
|
||||||
|
|
||||||
|
|
||||||
def cmd_off():
|
def cmd_off():
|
||||||
|
|
@ -160,16 +180,16 @@ def cmd_off():
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print("Usage: mullvad on <city or country> | mullvad off | mullvad status")
|
print("Usage: tailscale-mullvad on <city or country> | tailscale-mullvad off | tailscale-mullvad status")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
cmd = sys.argv[1].lower()
|
cmd = sys.argv[1].lower()
|
||||||
|
|
||||||
if cmd == "on":
|
if cmd == "on":
|
||||||
if len(sys.argv) < 3:
|
if len(sys.argv) < 3:
|
||||||
print("Usage: mullvad on <city or country>")
|
print("Usage: tailscale-mullvad on <city or country>")
|
||||||
print(" e.g. mullvad on amsterdam")
|
print(" e.g. tailscale-mullvad on amsterdam")
|
||||||
print(" e.g. mullvad on netherlands")
|
print(" e.g. tailscale-mullvad on netherlands")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
cmd_on(sys.argv[2])
|
cmd_on(sys.argv[2])
|
||||||
|
|
||||||
|
|
@ -181,7 +201,7 @@ def main():
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(f"Unknown command: {cmd}")
|
print(f"Unknown command: {cmd}")
|
||||||
print("Usage: mullvad on <city or country> | mullvad off | mullvad status")
|
print("Usage: tailscale-mullvad on <city or country> | tailscale-mullvad off | tailscale-mullvad status")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue