Giter Club home page Giter Club logo

Comments (29)

zhuhaow avatar zhuhaow commented on July 18, 2024

https://developer.apple.com/documentation/networkextension/neproxysettings

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

感谢您的回复,这个我试过,但好像不起作用,是否需要在PacketTunnelProvide里面做别的处理?
以下是我的代码。运行起来后,IP并不是https代理服务器的IP.

PacketTunnelProvider.m
- (void)startTunnelWithOptions:(NSDictionary *)options completionHandler:(void (^)(NSError *))completionHandler {
    NEIPv4Settings *ipv4Settings = [[NEIPv4Settings alloc] initWithAddresses:@[@"192.0.2.1"] subnetMasks:@[@"255.255.255.0"]];
    
    NSArray *dnsServers = @[@"8.8.8.8"];
    ipv4Settings.includedRoutes = @[[NEIPv4Route defaultRoute]];
    NEPacketTunnelNetworkSettings *settings = [[NEPacketTunnelNetworkSettings alloc] initWithTunnelRemoteAddress:@"192.0.2.2"];
    settings.IPv4Settings = ipv4Settings;
    settings.MTU = @(1500);
    NEProxySettings* proxySettings = [[NEProxySettings alloc] init];
    NSInteger proxyServerPort = 443;
    NSString *proxyServerName = @"xxxx.xxxx.xxxx";
    proxySettings.HTTPSEnabled = YES;
    proxySettings.HTTPSServer = [[NEProxyServer alloc] initWithAddress:proxyServerName port:proxyServerPort];
    proxySettings.autoProxyConfigurationEnabled = NO;
    proxySettings.excludeSimpleHostnames = YES;
    settings.proxySettings = proxySettings;
    NEDNSSettings *dnsSettings = [[NEDNSSettings alloc] initWithServers:dnsServers];
    settings.DNSSettings = dnsSettings;
    [self setTunnelNetworkSettings:settings completionHandler:^(NSError * _Nullable error) {
        if (error) {
            if (completionHandler) {
                completionHandler(error);
            }
        }else{
            if (completionHandler) {
                completionHandler(nil);
            }
        }
    }];
}

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

明白了,您的源码demo里面有这个转换处理吗?感激不尽

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

我想的就是填入一个https代理服务器的地址,连接后,网络请求通过代理发出,IP地址也会变成代理服务器的IP地址

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

用了PAC之后是不是可以不需要用NEKit的HttpsAdapter呢,只需要用我原来的代码,也就是NEProxySettings就可以了达到我的目标吗?

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

再次感谢大佬,我试试

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

您好,按照您的建议试了一下,连接上之后还是无网络,我的代理服务器肯定是正常的,因为PC浏览器可以正常使用代理。以下是代码片段。感觉我就差最后一步了。。

 NEPacketTunnelNetworkSettings *settings = [[NEPacketTunnelNetworkSettings alloc] initWithTunnelRemoteAddress:@"192.0.2.2"];
    settings.IPv4Settings = ipv4Settings;
    settings.MTU = @(1500);
    NEProxySettings* proxySettings = [[NEProxySettings alloc] init];
    NSInteger proxyServerPort = 443;
    NSString *proxyServerName = @"example.myproxy.com";
    proxySettings.HTTPSEnabled = YES;
    proxySettings.HTTPSServer = [[NEProxyServer alloc] initWithAddress:proxyServerName port:proxyServerPort];
    proxySettings.autoProxyConfigurationEnabled = YES;
    proxySettings.proxyAutoConfigurationURL = [NSURL URLWithString:@"https://example.mypac.com/pac.txt"];
    //proxySettings.excludeSimpleHostnames = YES;
    settings.proxySettings = proxySettings;

其中https://example.mypac.com/pac.txt的内容如下,格式应该也没问题。

function FindProxyForURL(url, host) {
    return "HTTPS example.myproxy.com:443"
}

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

您好,去掉httpsserver相关后,就只剩以下这几行代码了,好像还是有问题

NEProxySettings* proxySettings = [[NEProxySettings alloc] init];
proxySettings.autoProxyConfigurationEnabled = YES;
proxySettings.HTTPSEnabled = YES;
proxySettings.proxyAutoConfigurationURL = [NSURL 
URLWithString:@"https://example.mypac.com/pac.txt"];
settings.proxySettings = proxySettings;

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

您好,去掉HTTPSEnabled之后,就只剩与PAC相关的代码了。似乎还是没有网络。有没有可能是其他的比如ipv4setting等设置问题?

NEProxySettings* proxySettings = [[NEProxySettings alloc] init];
proxySettings.autoProxyConfigurationEnabled = YES;
proxySettings.proxyAutoConfigurationURL = [NSURL
URLWithString:@"https://example.mypac.com/pac.txt"];
settings.proxySettings = proxySettings;

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

您好,defaultRoute去掉后,网络正常,但是IP是本机IP,不是代理服务器的IP

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

您好,matchDomains也去掉了。现在整体代码如下:

- (void)startTunnelWithOptions:(NSDictionary *)options completionHandler:(void (^)(NSError *))completionHandler
{
    NEIPv4Settings *ipv4Settings = [[NEIPv4Settings alloc] initWithAddresses:@[@"192.0.2.1"] subnetMasks:@[@"255.255.255.0"]];

    NSArray *dnsServers = @[@"8.8.8.8"];
    NEPacketTunnelNetworkSettings *settings = [[NEPacketTunnelNetworkSettings alloc] initWithTunnelRemoteAddress:@"192.0.2.2"];
    settings.IPv4Settings = ipv4Settings;
    settings.MTU = @(1500);
    NEProxySettings* proxySettings = [[NEProxySettings alloc] init];
    proxySettings.autoProxyConfigurationEnabled = YES;
proxySettings.proxyAutoConfigurationURL = [NSURL
URLWithString:@"https://example.mypac.com/pac.txt"];
    settings.proxySettings = proxySettings;
    NEDNSSettings *dnsSettings = [[NEDNSSettings alloc] initWithServers:dnsServers];
    settings.DNSSettings = dnsSettings;
    [self setTunnelNetworkSettings:settings completionHandler:^(NSError * _Nullable error) {
        if (error) {
            if (completionHandler) {
                completionHandler(error);
            }
        }else{
            if (completionHandler) {
                completionHandler(nil);
            }
        }
    }];
}

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

所以还是需要借助您这个httpAdapter吗?

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

你之前有写过matchDomains吗?
加上了这一行么?
https://github.com/zhuhaow/Specht/blob/cfd35278f05eef0cbf20f1e53a477947f38388dd/SpechtTunnelPacketProvider/PacketTunnelProvider.swift#L56

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

您好,之前没有写matchDomains这个参数,刚才加上了设置proxySettings.matchDomains = [""],与刚才一样的现象,有网络但IP是本机IP

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

你怎么测的ip

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

就是在safari里面打开测IP网站,比如百度搜索IP.

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

pac服务器访问日志有记录么

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

您好,我现在没权限访问pac服务器,但我直接把js脚本写到ios代理里了。但是这样也是不行的。 :(

proxySettings.proxyAutoConfigurationJavaScript = @"function FindProxyForURL(url, host) { return \"HTTPS example.myproxy.com:443\"}";

from nekit.

zhuhaow avatar zhuhaow commented on July 18, 2024

from nekit.

qinghuawen avatar qinghuawen commented on July 18, 2024

好的,不好意思打扰您这么久,网上这方面的资料确实太少了。我再自己研究一下,非常感谢!

from nekit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.