Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if on VPN before download of Software Update #40

Open
tranziq opened this issue Oct 31, 2022 · 9 comments
Open

Check if on VPN before download of Software Update #40

tranziq opened this issue Oct 31, 2022 · 9 comments
Labels
enhancement New feature or request
Milestone

Comments

@tranziq
Copy link

tranziq commented Oct 31, 2022

Downloading software updates while on VPN can be very bandwidth demanding on most corporate infrastructure. We currently have in place a VPN check that we added to Super v2 for consideration to be placed as optional in the Main Code

checkVPN() {
local onPPP=$(ifconfig | grep -iv inet6 | grep ppp0 | wc -l | sed 's/ //g')
local onIPSEC=$(ifconfig | grep -iv inet6 | grep utun | grep -i noarp | wc -l | sed 's/ //g')
    if [[ ${onPPP} -gt 0 || ${onIPSEC} -gt 0 ]]; then
		echo " >>> Active VPN connection detected! Should not Install or run SUPER while connected to VPN!... Bail, Bail, Bail..."
    	exit 1
    fi
}

this confirm works with Forticlient and Cisco Anyconnect in our environment with Super v2

@Macjutsu Macjutsu added the enhancement New feature or request label Oct 31, 2022
@Macjutsu
Copy link
Owner

Good feature request! However, this likely won't be implemented until after v3.0 ships.

@Macjutsu Macjutsu added this to the v4.0 milestone Oct 31, 2022
@tranziq
Copy link
Author

tranziq commented Feb 14, 2023

I got this working in V3b6 if your interested:
Hit me up in #super in slack (Brent David)

Mon Feb 13 15:05:17: Status: Active VPN connection detected!

@Macjutsu
Copy link
Owner

Depends... is this specific to one VPN vendor or can it be used generically?

@scoobydooxp
Copy link

Unfortunately this does not work with Palo Alto Global Protect 6.x.

@tranziq - Which VPN software do you use?

@sean-alex
Copy link

the checkVPN() function does not work on Ivanti Secure Access Client. Both variables output "0", but a VPN connection is detected at "greater than" zero for either variable.

There is nothing vendor-related in the code, so makes me think there is a typo in code, or code is not accurate in detecting VPN status.

@smilieK
Copy link

smilieK commented Jul 14, 2023

Here is what I use to check for Global Protect VPN being connected. Maybe it will work for others.

ifconfigResults=$( ifconfig )
getVPNIP=$( echo "$ifconfigResults" 2> /dev/null | grep -v "broadcast" | grep "0xffffffff" | awk '{print $2}' )
echo "$getVPNIP"
if [ "$getVPNIP" != "" ]; then # If Computer has a IP
	pingResults=$( ping -t 3 "$getVPNIP" 2> /dev/null | grep "bytes from $getVPNIP: icmp_seq=" | grep "time=") # if Results, Computer is Connected to VPN, Computer can hold unto an old VPN IPG in a UTUNX
	if [ "$pingResults" != "" ]; then # If Results blank; Not on VPN
		echo "Computer 'IS' connected to VPN"
		echo "Current VPN IP: $getVPNIP"
		onVPN="Yes"
	else # VPN NOT Connected
		echo "Computer 'IS NOT' connected to VPN"
		echo "Last VPN IP: $getVPNIP"
		onVPN="No"		
	fi
else # VPN Found, but no IP for the uTun interface found
	echo "No VPN IP Address found"
	onVPN="No"
fi

@sean-alex
Copy link

@smilieK, unfortunately, your code is partially, but not completely, accurate with Ivanti Secure Client.
When connected to VPN, your code reports that I am not connected to VPN, though it picks up an IP address.

my output:

10.xx.xx.xx
Computer 'IS NOT' connected to VPN
Last VPN IP: 10.xx.xx.xx

I thought counting "tun" would work, but that is not accurate as not all VPN solutions use "tun" (some use the ipsec interface, for example).

I cheated and asked Apple enterprise support and, according to that engineer, the only way that they found to consistently way is to detect the IP --> IP string.

ifconfig | grep -c -e '-->'

If VPN exists, then you should receive an output greater than 0.

So, try this code and see if it works in your VPN; it reliably detected the Ivanti Secure Client VPN.

@iDrewbs
Copy link

iDrewbs commented Jul 18, 2023

I ran ifconfig | grep -c -e '-->' with Cisco AnyConnect and it returned a value of 1, so it looks like it works for Ciscos VPN

@smilieK
Copy link

smilieK commented Jul 24, 2023

@sean-alex

I get 1 as a result if on or off VPN, until reboot then I get 0 for result until I connect to vpn. :(

even after VPN disconnected this is found:
utun3: flags=8050<POINTOPOINT,RUNNING,MULTICAST> mtu 1400
inet 10.xxx.xxx.xxx --> 10.xxx.xxx.xxx netmask 0xffffffff

thats why I had the ping in my code, to see if the Ping replies or not. if reply VPN connected, if no reply or error then not connected to vpn.

@Macjutsu Macjutsu modified the milestones: v4.0.0, v4.1.0 Oct 23, 2023
@Macjutsu Macjutsu modified the milestones: v5.0.0, v5.x.x Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants