Get-VPNConnectionInfo
Overview
The Get-VPNConnectionInfo function checks if the current internet connection is made through one of the known VPN providers. It fetches the current IP information from ipapi.co and compares the organization name (org field) against a predefined list of VPN providers.
Requirements
- PowerShell 5.1 or higher.
- An Internet connection to perform queries to
ipapi.co. -
knownVPNproviders.jsonfile in the same directory as the script.
The format of the knownVPNproviders.json file.
This JSON file should contain an array of strings, each representing the name of a VPN provider recognized in the org field of a response from ipapi.co or ipinfo.io or other similar online services. The file should be structured as follows:
["VPNProviderName1", "VPNProviderName2", "VPNProviderName3"]
Replace "VPNProviderName1"`,"VPNProviderName2", and"VPNProviderName3" with the real names of the VPN providers you want to recognize. This can be your employer's VPN provider, a personal VPN service, or any other VPN provider you want to discover. The main thing is that this provider should provide specific information in the org field for whois services like ipapi.co/ipinfo.io. So if the org field is empty or non-unique. it can be confusing. but this doesn't happen very often.
Usage.
- Make sure that the
Get-VPNConnectionInfofunction and theknownVPNproviders.jsonfile are in the same directory. - Create the
Get-VPNConnectionInfo.ps1script file in a PowerShell session. You can do this by navigating to the script directory and running the. .\Get-VPNConnectionInfo.ps1command. - Call the function with
Get-VPNConnectionInfo.
Adding it to a PowerShell profile
For convenience, you can add the function to your PowerShell profile so that it is automatically available in every session:
- Open the PowerShell profile file for editing. If you do not know where it is located, find it by typing
$PROFILEin the PowerShell window. - Add the following line to the profile file:
. "C:\path\to\to\Get-VPNConnectionInfo.ps1"
Replace "C:\path\to\to\Get-VPNConnectionInfo.ps1" with the actual path to your script.
- Save the profile file and restart PowerShell.
The
Get-VPNConnectionInfofunction will now be available in every session.
Function Details.
- Input: None.
-
Output: A custom PowerShell object with the following properties:
-
connectedVPN: a boolean value indicating whether or not the current connection is being made through a known VPN provider. -
connect_info: An object containing information about the IP connection, including the name of a potentially suitable VPN provider. You can assume that if the provider name includes the word VPN, it is a suitable service.
-
The published code has an open license. If you have suggestions, pull requests are welcome.
Top comments (2)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.