ios 防止app被抓包(判断网络请求是否设置了代理)

判断ios app是否被抓包了(抓包工具是charles或是fiddler目前不知道怎么获取)

导入系统框架 获取系统代理设置 

可获取到代理服务器的地址、端口号、链接类型(http || https)

获取到app被抓包可以进行终止数据传输

#import

- (BOOL)getProxyStatus {

    NSDictionary*proxySettings =  (__bridgeNSDictionary*)(CFNetworkCopySystemProxySettings());

    NSArray*proxies = (__bridgeNSArray*)(CFNetworkCopyProxiesForURL((__bridgeCFURLRef_Nonnull)([NSURLURLWithString:@"http://www.baidu.com"]), (__bridgeCFDictionaryRef_Nonnull)(proxySettings)));

    NSDictionary*settings = [proxiesobjectAtIndex:0];

    NSLog(@"host=%@", [settings objectForKey:(NSString *)kCFProxyHostNameKey]);

    NSLog(@"port=%@", [settings objectForKey:(NSString *)kCFProxyPortNumberKey]);

    NSLog(@"type=%@", [settings objectForKey:(NSString *)kCFProxyTypeKey]);

    if ([[settings objectForKey:(NSString *)kCFProxyTypeKey] isEqualToString:@"kCFProxyTypeNone"]){

        //没有设置代理

        returnNO;

    }else{

        //设置代理了

        returnYES;

    }

}

- (id)fetchSSIDInfo {

    NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();

    NSLog(@"Supported interfaces: %@", ifs);

    idinfo =nil;

    for(NSString*ifnaminifs) {

        info = (__bridge_transferid)CNCopyCurrentNetworkInfo((__bridgeCFStringRef)ifnam);

        NSLog(@"代理是%@ => %@", ifnam, info);

        if(info && [infocount]) {break; }

    }

    returninfo;

}

你可能感兴趣的:(ios 防止app被抓包(判断网络请求是否设置了代理))