iOS-代理检测

当我们开发移动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());
// 获取代理的信息 - url一般都填baidu
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;
}