tags:

views:

87

answers:

5

Is there any way to detect if I am connected to a VPN using standard windows APIs in C?

Basically I have a client that has to sync with a server but only if the VPN is connected. This could be a standard windows VPN client or a Citrix.

Is RAS helpful here?

thank you, code is appreciated.

EDIT: to make it clearer.

This is a client that will run on our customer's computer and they set the VPN and server however they want. So I wanted to know if windows keeps a setting somewhere that I can read via an API or registry or WMI or whatever that can tell me VPN: no or yes and if yes the info.

+1  A: 

Your IP space should be different if you're on VPN or not - if the VPN is set up right, the server shouldn't even be accessible unless you're on the VPN. You could try to ping the server, and only try to perform the sync if you get a response?

Curtis
I was looking for something more definitive (see previous comment)
Jessica
+1  A: 

With the VPN I suspect you able to access resources that don't exists otherwise. So you could PING test a server on the VPN network. ICMP is the protocol for ping.

Here is some examples: http://www.alhem.net/project/ex10/index.html

Robert Love
i thought about it before but i need to get the IP and domain name to be able to sync. So in cases where the computer is connected to a VPN and the internet when I request the IP or a domain sometimes I get the information about the internet and not the one from the VPN. It depends on whether the 1st connected "NIC" is the VPN or not so I was looking for something more definitive.
Jessica
What I guess Robert means, is that you can PING a network node that does not respond when contacted from the internet, but does when contacted from inside the VPN.
gnud
not a possible solution but I want to close this question
Jessica
A: 

I'm fairly certain that one of the selling points of VPN is that userland applications should be, on the whole, entirely unaware of its existence. Your best course of action is likely to query, using COM or some other form of IPC, known VPN provider services, or just see if they are alive and/or active, and infer the situation based on this evidence.

Williham Totland
do you think querying the WMI will help? if yes, what object?
Jessica
@Jessica: This; I cannot say. I'm merely talking about my general experiences with VPN networks.
Williham Totland
A: 

I have looked for vendor specific registry settings to determine if the tunnel is active. This works well with Nortel and Cisco VPN clients.

vonderbrink
could you give an example?
Jessica
A: 

Can your app lookup the IP of a domain name that's only available through the VPN? If the name lookup fails, you're not on the VPN. If the general Internet can't query the DNS server on the VPN, this may be a workable solution (but maybe not generalized enough for your needs?). You can then try connecting to that IP -- something that will only succeed if you're on the VPN.

You could even have a public DNS server provide the IP address. Just use a special hostname that never resolves to a public IP. If the VPN isn't up, you won't be able to reach that address.

tomlogic
you are assuming that I know the address. I don't. This is a client that will run on our customer's computer and they set the VPN and server however they want. So I wanted to know if windows keeps a setting somewhere that I can read via an API or registry or WMI or whatever that can tell me VPN: no or yes and if yes the info.
Jessica