Last active
March 30, 2017 17:12
-
-
Save phillymjs/cdab4c4aedc98fe3b1113f0484971c47 to your computer and use it in GitHub Desktop.
Displays a dialog with the active network port and its IP address, or the IP in use by the Cisco AnyConnect VPN client.
This file contains hidden or 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
try | |
--Check the Cisco AnyConnect client state | |
(do shell script "/opt/cisco/anyconnect/bin/vpn state | grep \"state: Connected\"") as string | |
--If we get here then we're connected, so return the Cisco IP information | |
set activeNetworkPortName to "Cisco AnyConnect VPN" | |
set currentIP to do shell script "/opt/cisco/anyconnect/bin/vpn stats | grep \"Client Address (IPv4):\" | awk '{print $4}'" | |
on error | |
--If we end up here then there is no VPN connection, therefore we're on an Apple network port, so we need to figure out which one and return the IP | |
set activeNetworkPortID to do shell script "/sbin/route -n get 0.0.0.0 2>/dev/null | /usr/bin/awk '/interface: / {print $2}'" | |
set activeNetworkPortName to do shell script "/usr/sbin/networksetup -listnetworkserviceorder | /usr/bin/grep 'Hardware Port' | grep " & activeNetworkPortID & " | /usr/bin/cut -c 17- | /usr/bin/awk 'BEGIN {FS=\",\"}; {print $1}'" | |
set currentIP to do shell script "/usr/sbin/ipconfig getifaddr " & activeNetworkPortID | |
end try | |
set iconpath to (path to startup disk) & "System:Library:PreferencePanes:Network.prefPane:Contents:Resources:Network.icns" as string | |
display dialog "Connected via " & activeNetworkPortName & " | |
IP address: " & currentIP buttons {"OK"} default button "OK" with title "Current Network Connection Info" with icon file iconpath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rewritten to use the AnyConnect "state" command to determine connection state instead of just trying to get the VPN IP.