Skip to content

Instantly share code, notes, and snippets.

@martinhering
Last active December 25, 2015 04:49
Show Gist options
  • Save martinhering/6919550 to your computer and use it in GitHub Desktop.
Save martinhering/6919550 to your computer and use it in GitHub Desktop.
OS X Tethering Check
#import <CoreWLAN/CoreWLAN.h>
#import <SystemConfiguration/SystemConfiguration.h>
extern CFStringRef _SCNetworkInterfaceGetIOPath(SCNetworkInterfaceRef interface);
@interface CWNetwork (Voodoo)
- (NSDictionary*) scanRecord;
@end
- (BOOL) tetheringOverWifiActive
{
CWInterface* interface = [CWInterface interface];
NSSet* networks = [interface scanForNetworksWithSSID:nil error:nil];
for(CWNetwork* network in networks)
{
if ([interface.ssid isEqualToString:network.ssid]) {
NSDictionary* scanRecord = [network scanRecord];
BOOL networkCreatedByIOSDevice = (scanRecord[@"IOS_IE"] != nil);
return networkCreatedByIOSDevice;
}
}
return NO;
}
- (BOOL) tetheringOverUSBActive
{
NSArray* interfaces = (__bridge NSArray*)SCNetworkInterfaceCopyAll();
for(id i in interfaces) {
SCNetworkInterfaceRef interface = (__bridge SCNetworkInterfaceRef)i;
NSString* type = (__bridge NSString*)SCNetworkInterfaceGetInterfaceType(interface);
NSString* address = (__bridge NSString*)_SCNetworkInterfaceGetIOPath(interface);
if ([type isEqualToString:@"Ethernet"] && [address rangeOfString:@"AppleUSBEthernetHost"].location != NSNotFound && [address rangeOfString:@"iPhone"].location != NSNotFound) {
return YES;
}
}
return NO;
}
@martinhering
Copy link
Author

You can't ship this code in the App Store though as you need private methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment