Created
September 7, 2024 23:59
-
-
Save kareemlukitomo/1868a12294261e840e55337a392bbe72 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Get the list of exit nodes, skipping the first two lines (header) | |
exit_nodes=$(sudo tailscale exit-node list | tail -n +3 | grep -E '^\s*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s+') | |
# Add a "Disable exit node" option | |
echo -e "Disable exit node" > tmp_exit_nodes | |
echo "$exit_nodes" >> tmp_exit_nodes | |
# Use fzf to select an exit node, formatting as 'Country - City' and previewing IP and Hostname | |
selected_node=$(cat tmp_exit_nodes | \ | |
fzf --prompt="Select an exit node: " \ | |
--header="Select an exit node or choose to disable" \ | |
) | |
# Cleanup temporary file | |
rm tmp_exit_nodes | |
# Check if the user selected "Disable" | |
if [[ "$selected_node" == "Disable exit node"* ]]; then | |
echo "Disabling exit node..." | |
sudo tailscale set --exit-node= | |
else | |
# Extract the IP from the selected option | |
exit_ip=$(echo "$selected_node" | awk '{print $1}' | cut -d' ' -f1) | |
echo "Setting exit node to $selected_node" | |
sudo tailscale set --exit-node="$exit_ip" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment