Last active
December 25, 2015 04:49
-
-
Save martinhering/6919550 to your computer and use it in GitHub Desktop.
OS X Tethering Check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can't ship this code in the App Store though as you need private methods.