ios 判断手机是否开启了代理

在研究逆向的时候,发现有些app只要是开启了代理,然后就自动退出了。原理就是通过获取网络的代理状态,然后我exit(1).

 CFDictionaryRef proxySettings = CFNetworkCopySystemProxySettings();

    NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];

   NSArray *proxies = ((__bridge NSArray *)CFNetworkCopyProxiesForURL(((__bridge CFURLRef)url), proxySettings));

    NSDictionary*setting = proxies[0];


    NSLog(@"host=%@",setting[(__bridge NSString *)kCFProxyHostNameKey]);

    NSLog(@"port=%@",setting[(__bridge NSString *)kCFProxyTypeKey]);

    //监听的类型

    NSLog(@"type=%@",setting[(__bridge NSString *)kCFProxyPortNumberKey]);

    if ([setting[(__bridge NSString *)kCFProxyPortNumberKey] isEqualToString:(__bridge NSString *)kCFProxyTypeNone]) {

        //没有设置代理

    }else{

        exit(1);

    }

你可能感兴趣的:(ios 判断手机是否开启了代理)