Reputation: 21488
Using .NET, is there a way to retrieve the external IP of a PC if they are connected to a VPN and using the VPN as the internet gateway? My end goal is to detect if the client PC is truly on the network or if they are at a remote location.
EDIT: After reading some of these answers, I should be a little more specific. I guess what I'm looking for is a programmatic way of bypassing the VPN to check the true external IP of the laptop. Is this possible?
Upvotes: 2
Views: 3097
Reputation: 4727
Also, if you are at the client, you could run ROUTE PRINT on windows and parse the output searching for the VPN specific entries. Try running the command when connected to the VPN and when connected directly and find the differences. Besides the physical adapters you should see a VPN adapter and all external routes going through it. If you want to bypass the VPN to get the external IP, which you would probably do by accessing and external server, you would have to add a route to that server through the ethenet adapter. But I have used VPN clients that block that, meaning that all traffic must go through the VPN, so this might not work for you.
Upvotes: 1
Reputation: 139
usually when you are connected to a vpn you have an ip of a subnet that not is the same of the subnet when you are phisically connected, but if this is not the case, you could try to run a tracert an get the response, if the firewall that manage the vpn is not the same of the router that provide connection to the network, you got it, only parse the response.
Other way to do this is get the name of the adapter with the ip, if is the vpn adapter you got it.
Upvotes: 0
Reputation: 35478
If you are a server, say HTTP server, you cannot, as one of the main purposes of VPN is to provide anonymity. The machine goes on to internet via VPN, so unless client bypasses vpn and sends the real ip address to you, you can't.
Upvotes: 0
Reputation: 150198
You cannot directly detect the "real" IP, but you may be able to infer whether they are on the network by looking at factors specific to your network topology.
For example, ping times for computers on the local network will be drastically different than ones that are external. That is not 100% perfect, but should give you a very solid indicator.
The route may also be different (does traceroute show different routes for devices on the local network vs. remote devices?)
Upvotes: 0
Reputation: 4727
The easiest way would be to assign a range of IP's specific to the VPN, then just test to see if the internal IP is in that range.
Upvotes: 0
Reputation: 604
I don't think so. However you can detect if the client comes from VPN by checking if IP that you got has been used a lot, or is known to host a VPN server (you can have a list).
Upvotes: 1