Skip to content

Instantly share code, notes, and snippets.

@isomorpheric
Forked from pjobson/getdisplay.sh
Created June 30, 2022 16:14
Show Gist options
  • Select an option

  • Save isomorpheric/7ed3fff5b1d4833784a5b4fe6ebbd5f8 to your computer and use it in GitHub Desktop.

Select an option

Save isomorpheric/7ed3fff5b1d4833784a5b4fe6ebbd5f8 to your computer and use it in GitHub Desktop.

Revisions

  1. @pjobson pjobson revised this gist Apr 8, 2022. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions getdisplay.sh
    Original file line number Diff line number Diff line change
    @@ -9,23 +9,23 @@ fi
    VPNIFACE=$1
    DEFIFACE=$2

    VPNCMD="/mnt/c/Windows/system32/netsh.exe interface show interface \"${VPNIFACE}\" | grep \"Disconnected\""
    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}\" | grep \"Disconnected\""
    DEFCMD="/mnt/c/Windows/system32/netsh.exe interface show interface \"${DEFIFACE}\""
    DEFRES=$(eval "$DEFCMD")

    if [[ "$DEFRES" == *"Disconnected"* ]] && [[ "$VPNRES" == *"Disconnected"* ]]; then
    echo "Both interfaces are disconnected."
    exit 0
    fi

    # Set the IP Command to use the default, we'll overwrite it with the VPN if it is not disconnected, below.
    IPCMD="/mnt/c/Windows/system32/netsh.exe interface ip show address \"${DEFIFACE}\""
    IPCMD=""


    if [[ "$DEFRES" == *"Disconnected"* ]]; then
    IPCMD="/mnt/c/Windows/system32/netsh.exe interface ip show addresses \"${VPNIFACE}\""
    if [[ "$VPNRES" == *"Disconnected"* ]]; 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 \"IP Address\" | perl -lpe 's/\s+IP Address:\s+(\d+.+?)[\r\n]*\$/\$1:0.0/'"
  2. @pjobson pjobson created this gist Apr 7, 2022.
    33 changes: 33 additions & 0 deletions getdisplay.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/bin/bash

    # Check for user input
    if [ -z "$1" ] || [ -z "$2" ]; then
    echo "Expects: getdisplayip.sh \"VPN Interface\" \"Default Interface\""
    exit 0
    fi

    VPNIFACE=$1
    DEFIFACE=$2

    VPNCMD="/mnt/c/Windows/system32/netsh.exe interface show interface \"${VPNIFACE}\" | grep \"Disconnected\""
    VPNRES=$(eval "$VPNCMD")

    DEFCMD="/mnt/c/Windows/system32/netsh.exe interface show interface \"${DEFIFACE}\" | grep \"Disconnected\""
    DEFRES=$(eval "$DEFCMD")

    if [[ "$DEFRES" == *"Disconnected"* ]] && [[ "$VPNRES" == *"Disconnected"* ]]; then
    echo "Both interfaces are disconnected."
    exit 0
    fi

    # Set the IP Command to use the default, we'll overwrite it with the VPN if it is not disconnected, below.
    IPCMD="/mnt/c/Windows/system32/netsh.exe interface ip show address \"${DEFIFACE}\""


    if [[ "$DEFRES" == *"Disconnected"* ]]; then
    IPCMD="/mnt/c/Windows/system32/netsh.exe interface ip show addresses \"${VPNIFACE}\""
    fi

    IPCMD="${IPCMD} | grep \"IP Address\" | perl -lpe 's/\s+IP Address:\s+(\d+.+?)[\r\n]*\$/\$1:0.0/'"

    echo $(eval "$IPCMD")