/etc/hosts with NSURLProtocol
Objective-C
Latest commit 1164bfe Apr 16, 2014 @mattt Adding workspace
Permalink
Failed to load latest commit information.
Example Initial Commit Apr 16, 2014
NSEtcHosts.xcworkspace Adding workspace Apr 16, 2014
NSEtcHosts Initial Commit Apr 16, 2014
LICENSE Initial Commit Apr 16, 2014
README.md Update README.md Apr 16, 2014

README.md

NSEtcHosts

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.

Usage

[NSURLProtocol registerClass:[EtcHostsURLProtocol class]];
[EtcHostsURLProtocol configureHostsWithBlock:^(id <EtcHostsConfiguration> configuration) {
    [configuration resolveHostName:@"google.com" toIPAddress:@"98.138.253.109"];
}];

NSEtcHosts in Action

NSURL *URL = [NSURL URLWithString:@"http://google.com"];
[webView loadRequest:[NSURLRequest requestWithURL:URL]];

Contact

Mattt Thompson @mattt

License

NSEtcHosts is available under the MIT license. See the LICENSE file for more info.