Skip to content

Instantly share code, notes, and snippets.

@J-Pster
Created October 4, 2022 04:19
Show Gist options
  • Save J-Pster/187434642e2ff2ed46452f27027db5e2 to your computer and use it in GitHub Desktop.
Save J-Pster/187434642e2ff2ed46452f27027db5e2 to your computer and use it in GitHub Desktop.
Script para pegar o IP da Interface
#!/bin/bash
# Verifica o input do usuário
if [ -z "$1" ] || [ -z "$2" ]; then
echo "É esperado: getdisplayip.sh \"Interface 01\" \"Interface 02\""
exit 0
fi
VPNIFACE=$1
DEFIFACE=$2
VPNCMD="/mnt/c/Windows/system32/netsh.exe interface show interface \"${VPNIFACE}\""
VPNRES=$(eval "$VPNCMD")
DEFCMD="/mnt/c/Windows/system32/netsh.exe interface show interface \"${DEFIFACE}\""
DEFRES=$(eval "$DEFCMD")
if [[ "$DEFRES" == *"Desconectado"* ]] && [[ "$VPNRES" == *"Desconectado"* ]]; then
echo "As duas interfaces estão desconectadas."
exit 0
fi
IPCMD=""
if [[ "$VPNRES" == *"Desconectado"* ]]; then
IPCMD="/mnt/c/Windows/system32/netsh.exe interface ip show addresses \"${DEFIFACE}\""
else
IPCMD="/mnt/c/Windows/system32/netsh.exe interface ip show address \"${VPNIFACE}\""
fi
IPCMD="${IPCMD} | grep \"Endereço IP\" | perl -lpe 's/\s+Endereço IP:\s+(\d+.+?)[\r\n]*\$/\$1:0.0/'"
echo $(eval "$IPCMD")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment