liao3841054 / NSEtcHosts

/etc/hosts with NSURLProtocol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

/etc/hosts with NSURLProtocol

License:MIT License


Languages

Language:Objective-C 100.0%