Skip to content

Instantly share code, notes, and snippets.

@adamsvoboda
Created July 24, 2020 19:09
Show Gist options
  • Save adamsvoboda/cf15e25181b87d2ba914c1da324a3f2e to your computer and use it in GitHub Desktop.
Save adamsvoboda/cf15e25181b87d2ba914c1da324a3f2e to your computer and use it in GitHub Desktop.
#!/bin/bash
# PWK / TryHackMe / HTB / etc.
# Automatically checks for VPN ip addresses in this order, then exports the first one it finds:
# TAP0 -> TUN0 -> ETH0 (non vpn)
# ~/.config/fish/config.fish
# set IP (bash /home/adam/.scripts/update-ip.sh)
# ~/.zshrc
# source /home/adam/.scripts/update-ip.sh
IP=""
IP1=`ip addr | grep inet | grep tap0 | awk -F" " '{print $2}'| sed -e 's/\/.*$//'`;
IP2=`ip addr | grep inet | grep tun0 | awk -F" " '{print $2}'| sed -e 's/\/.*$//'`;
IP3=`ip addr | grep inet | grep eth0 | awk -F" " '{print $2}'| sed -e 's/\/.*$//'`;
if [[ ! -z "$IP1" ]]
then
IP=$IP1
elif [[ ! -z "$IP2" ]]
then
IP=$IP2
else
IP=$IP3
fi
export IP;
echo "$IP";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment