From c90068c6f3f07d937ad1de58e671f81c8d9fb998 Mon Sep 17 00:00:00 2001 From: Eddy Date: Sat, 16 May 2026 02:11:29 +0200 Subject: [PATCH] Show external IP before and after Mullvad activation --- tailscale-mullvad | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tailscale-mullvad b/tailscale-mullvad index 1306c53..12317ee 100644 --- a/tailscale-mullvad +++ b/tailscale-mullvad @@ -11,6 +11,7 @@ import subprocess import sys import re import random +import time def _run_tailscale(args, timeout=30): @@ -118,6 +119,20 @@ def show_status(): 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): """Connect to a Mullvad exit node matching the given location.""" nodes = get_exit_nodes() @@ -139,6 +154,8 @@ def cmd_on(location): node = random.choice(matches) 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("Tearing down Tailscale...") _run_tailscale_live(["down", "--accept-risk=lose-ssh"]) @@ -146,7 +163,10 @@ def cmd_on(location): _run_tailscale_live( ["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"IP: {ip_before} -> {ip_after}") def cmd_off(): @@ -160,16 +180,16 @@ def cmd_off(): def main(): if len(sys.argv) < 2: - print("Usage: mullvad on | mullvad off | mullvad status") + print("Usage: tailscale-mullvad on | tailscale-mullvad off | tailscale-mullvad status") sys.exit(1) cmd = sys.argv[1].lower() if cmd == "on": if len(sys.argv) < 3: - print("Usage: mullvad on ") - print(" e.g. mullvad on amsterdam") - print(" e.g. mullvad on netherlands") + print("Usage: tailscale-mullvad on ") + print(" e.g. tailscale-mullvad on amsterdam") + print(" e.g. tailscale-mullvad on netherlands") sys.exit(1) cmd_on(sys.argv[2]) @@ -181,7 +201,7 @@ def main(): else: print(f"Unknown command: {cmd}") - print("Usage: mullvad on | mullvad off | mullvad status") + print("Usage: tailscale-mullvad on | tailscale-mullvad off | tailscale-mullvad status") sys.exit(1)