当我们开发移动App时候,为了避免别人抓包,所以我们要有自己的检测机制
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| - (BOOL)checkProxySetting { NSDictionary *proxySettings = (__bridge NSDictionary *)(CFNetworkCopySystemProxySettings()); NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"]; NSArray *proxies = (__bridge NSArray *)(CFNetworkCopyProxiesForURL((__bridge CFURLRef)(url), (__bridge CFDictionaryRef)(proxySettings))); if (proxies.count > 0) { NSString *proxyType = [proxies.firstObject objectForKey:(NSString *)kCFProxyTypeKey]; if (![proxyType isEqualToString:(__bridge NSString *)kCFProxyTypeNone]) { for (int i = 0; i < proxies.count; i++) { NSDictionary *settings = proxies[i]; if (i == 0) { NSLog(@"---------------代理配置---------------"); } NSLog(@"host: %@", [settings objectForKey:(NSString *)kCFProxyHostNameKey]); NSLog(@"port: %@", [settings objectForKey:(NSString *)kCFProxyPortNumberKey]); NSLog(@"type: %@", [settings objectForKey:(NSString *)kCFProxyTypeKey]); if (i == proxies.count - 1) { NSLog(@"-------------------------------------"); } else { NSLog(@"---------------------------"); } } return YES; } } return NO; }
|