As "diciu" wrote, you can query the System Configuration framework. The programmatic equivalent of the scutil command that he gave is something like
#import <SystemConfiguration/SystemConfiguration.h>
- (void)printPrimaryService {
SCDynamicStoreRef dynamicStoreDomainState = SCDynamicStoreCreate(NULL,
CFSTR("myApplicationName"),
NULL,
NULL);
if (dynamicStoreDomainState) {
NSString *netIPv4Key = [NSString stringWithFormat:@"%@/%@/%@/%@",
kSCDynamicStoreDomainState,
kSCCompNetwork,
kSCCompGlobal,
kSCEntNetIPv4];
NSMutableDictionary *netIPv4Dictionary = (NSMutableDictionary *) SCDynamicStoreCopyValue(dynamicStoreDomainState, (CFStringRef)netIPv4Key);
if (netIPv4Dictionary ) {
NSString *primaryService = [netIPv4Dictionary objectForKey:(NSString *)kSCDynamicStorePropNetPrimaryService];
if (primaryService) {
NSLog(@"primary service = \"%@\"\n", primaryService); /* When the Cisco VPN is active, I get "com.cisco.VPN" here */
}
[netIPv4Dictionary release];
}
CFRelease(dynamicStoreDomainState);
}
}
Using the above, you can tell if the Cisco VPN client is connected. You can then do something similar to get the DNS servers associated with the VPN connection. I compare the resulting DNS servers to the DNS server of my company to tell if I'm VPN'd into my company. Klunky, but it works and it's fast - no waiting for a ping to timeout.
Note that with the recent version of the Cisco VPN Client, Cisco published an API. Unfortunately, it's only for Microsoft Windows. Maybe they'll produce one for Macs some day.