Created
October 4, 2022 04:19
-
-
Save J-Pster/187434642e2ff2ed46452f27027db5e2 to your computer and use it in GitHub Desktop.
Script para pegar o IP da Interface
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 | |
# 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