/etc/hosts with NSURLProtocol
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Example
NSEtcHosts.xcworkspace
NSEtcHosts
LICENSE
README.md

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.