Get VPN Connection IP

With all the users working from we’re having issues remoting in to provide support. To get in obviously we need the VPN IP and not their local IP, but some users aren’t the best at supplying this and ping isn’t always reliable. Is there a way to get a user or computers VPN IP with the likes of Get-VPNConnection?

/u/wanderingbilby has a good suggestion that displays all interfaces and their IP’s.

But what if you want to only show the VPN connection? If the users are not the best at supplying the correct IP from ipconfig, unclear if this solution helps unless you are running it yourself. And even if you are, you still need to identify the VPN based on a string-based interface name. This is fraught with interpretation :wink:

How about we get all configured VPN connections and use that to filter the interfaces for the matching VPN connection;

$vpnConnections = Get-VpnConnection -AllUserConnection
$vpnConnectionRegex = $vpnConnections.name -join '|'
$InterfaceIPs = Get-NetIPAddress | where {$_.InterfaceAlias -match $vpnConnectionRegex} | Select InterfaceAlias,IpAddress
$InterfaceIPs

We use good old bginfo on all ours Covid-laptop

ask the VPN server, not the ignorant client.

I actually wrote something for this yesterday. Requires RemoteAccess module.

$servers = "server1","server2","server3"
foreach ($server in $servers) {
$info = Get-RemoteAccessConnectionStatistics -computername $server
foreach ($line in $info) {
$time = $line.ConnectionDuration 
$span = New-Timespan -seconds $time
$duration = "{0:hh\:mm\:ss}" -f ([timespan] $span)
$object = [PSCustomObject] @{
Server = $server
Username = $line.username
IP = $line.clientipaddress
Duration = $duration
}
$object
}
}

This will go out to each server and get a list of VPN connections, with the name of the server, the username connected, the IP address of the VPN connection, and the duration of the connection in hours:minutes:seconds.

There’s lots in the NetTCPIp module.

Get-NetIPAddress | Select InterfaceAlias,IpAddress

$script:ipaddress = (Get-WmiObject win32_networkadapterconfiguration -filter “ipenabled = ‘true’” | where {$_.dnsname -eq ‘yourdomain’}).IPAddress
If ([string]::IsNullOrWhitespace($script:ipaddress))
{$script:ipaddress = “Off VPN”}else{}

Usually we just have them Google “what is my ip”. Quick and requires no interaction between the machine just in case they aren’t savvy and aren’t actually connected.

Probably shouldn’t say where I work, but this works great for both when on network & VPN, and when the user is not yet on network to help trouble shoot their issues.

https://www.beyondtrust.com/remote-support

I was more just pointing out that Module with a quick example of one fucntion - yep you’d need to figure out how to filter to the connection you want. For example Get-VPNConnection does diddly for me because I use a vendor SSLVPN client.

That displays what I need locally from my machine, is there a way to grab the info from a remote machine? Using -ComputerName just errors

That is definitely a more challenging scenario.

You can use Invoke-Command to send a script block to the remote machine, execute it, and return the result.

I assumed you were running this on the remote machine. How can you target the remote machine if you don’t have the IP to start with?

just Curl one of the sites that provides your outgoing IP and parse the results.

Of course duh im stupid. It’s catch 22