NSEtcHosts uses NSURLProtocol
to intercept requests for specified host names, resolving them instead to a different IP address, similar to an /etc/hosts
file on a Unix system. (This does not actually affect the actual hosts file used by iOS, nor does it affect routing behavior outside of the application process)
This is a proof-of-concept, and is not intended for use in production.
[NSURLProtocol registerClass:[EtcHostsURLProtocol class]];
[EtcHostsURLProtocol configureHostsWithBlock:^(id <EtcHostsConfiguration> configuration) {
[configuration resolveHostName:@"google.com" toIPAddress:@"98.138.253.109"];
}];
NSURL *URL = [NSURL URLWithString:@"http://google.com"];
[webView loadRequest:[NSURLRequest requestWithURL:URL]];
NSEtcHosts is available under the MIT license. See the LICENSE file for more info.