Comments (15)
from nekit.
抱歉没看到,我目前的路由配置如下:
let ipv4Settings = NEIPv4Settings(addresses: ["192.169.89.1"], subnetMasks: ["255.255.255.0"])
ipv4Settings.includedRoutes = [NEIPv4Route.default()]
ipv4Settings.excludedRoutes = [
NEIPv4Route(destinationAddress: "10.0.0.0", subnetMask: "255.0.0.0"),
NEIPv4Route(destinationAddress: "100.64.0.0", subnetMask: "255.192.0.0"),
NEIPv4Route(destinationAddress: "127.0.0.0", subnetMask: "255.0.0.0"),
NEIPv4Route(destinationAddress: "169.254.0.0", subnetMask: "255.255.0.0"),
NEIPv4Route(destinationAddress: "172.16.0.0", subnetMask: "255.240.0.0"),
NEIPv4Route(destinationAddress: "192.168.0.0", subnetMask: "255.255.0.0"),
NEIPv4Route(destinationAddress: "17.0.0.0", subnetMask: "255.0.0.0"),
]
networkSettings.ipv4Settings = ipv4Settings
from nekit.
from nekit.
这是我startTunnel方法的实现代码:
override func startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void) {
let s5AdapterFactory = SOCKS5AdapterFactory(serverHost: "192.168.1.111", serverPort: 9287)
let allRule = AllRule(adapterFactory: s5AdapterFactory)
RuleManager.currentManager = RuleManager(fromRules: [allRule], appendDirect: false)
let networkSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "8.8.8.8")
networkSettings.mtu = 1500
let ipv4Settings = NEIPv4Settings(addresses: ["192.169.89.1"], subnetMasks: ["255.255.255.0"])
ipv4Settings.includedRoutes = [NEIPv4Route.default()]
ipv4Settings.excludedRoutes = [
NEIPv4Route(destinationAddress: "10.0.0.0", subnetMask: "255.0.0.0"),
NEIPv4Route(destinationAddress: "100.64.0.0", subnetMask: "255.192.0.0"),
NEIPv4Route(destinationAddress: "127.0.0.0", subnetMask: "255.0.0.0"),
NEIPv4Route(destinationAddress: "169.254.0.0", subnetMask: "255.255.0.0"),
NEIPv4Route(destinationAddress: "172.16.0.0", subnetMask: "255.240.0.0"),
NEIPv4Route(destinationAddress: "192.168.0.0", subnetMask: "255.255.0.0"),
NEIPv4Route(destinationAddress: "17.0.0.0", subnetMask: "255.0.0.0"),
]
networkSettings.ipv4Settings = ipv4Settings
if enablePacketProcessing {
let DNSSettings = NEDNSSettings(servers: ["8.8.8.8"])
DNSSettings.matchDomains = [""]
DNSSettings.matchDomainsNoSearch = false
networkSettings.dnsSettings = DNSSettings
RawSocketFactory.TunnelProvider = self
}
setTunnelNetworkSettings(networkSettings) { error in
guard error == nil else {
completionHandler(error)
return
}
if !self.started {
// 下面的观察者要检查网络变化并重启服务
// self.addObserver(self, forKeyPath: "defaultPath", options: .initial, context: nil)
if #available(iOSApplicationExtension 10.0, *) {
DDLog.add(DDOSLogger.sharedInstance, with: DDLogLevel.verbose)
DDOSLogger.sharedInstance.logFormatter = LogFormatter()
}
Opt.MAXNWTCPSocketReadDataSize = 60 * 1024 - 1
}
if self.started {
self.httpProxy.stop()
try! self.httpProxy.start()
} else {
self.httpProxy = GCDHTTPProxyServer(address: IPAddress(fromString: "127.0.0.1"), port: 6152)
try! self.httpProxy.start()
}
completionHandler(nil)
if self.enablePacketProcessing {
if self.started {
self.interface.stop()
}
if !self.started {
self.interface = TUNInterface(packetFlow: self.packetFlow)
let udpStack = UDPAssociateStack(serverHost: "192.168.1.111", serverPort: 9287)
self.interface.register(stack: udpStack)
let tcpStack = TCPStack.stack
tcpStack.proxyServer = self.httpProxy
self.interface.register(stack:tcpStack)
self.interface.start()
}
}
self.started = true
}
}
我能够在udp的input方法,收到dns要发送的udp包,我把包转发到代理服务器,代理服务器也返回udp包了。
from nekit.
from nekit.
你是说用电脑的dig命令吗?
fengMacmini:~ feng$ dig @8.8.8.8 www.google.com A
; <<>> DiG 9.10.6 <<>> @8.8.8.8 www.google.com A
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12285
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.google.com. IN A
;; ANSWER SECTION:
www.google.com. 145 IN A 31.13.85.16
;; Query time: 62 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Oct 03 14:07:35 CST 2019
;; MSG SIZE rcvd: 48
from nekit.
from nekit.
from nekit.
好~我先试试
from nekit.
from nekit.
不要指定8.8.8.8
from nekit.
dig没有指定8.8.8.8,但是NEDNSSettings有设定
from nekit.
大佬,我有几个关于dns的疑问,先抛开之前说的,希望能够解惑。
1.NEDNSSettings的作用是不是起到了把系统的dns更改为我设定的dns?如果不是的话,是用来干嘛?
2.如果我设置了NEProxySettings,也就是http代理,并且TUNInterface里面注册了DNSServer,那么我访问网页连接请求的时候,域名解析的dns会走系统的dns还是会被TUNInterface劫持,用DNSServer的设定去解析呢?
3.如果我用了DNSServer但是不用ip池,会有什么影响吗?文档上说的是为了进行反向查找,但是我想知道如果不用的话会有什么影响。
代码是这样的:
self.interface = TUNInterface(packetFlow: self.packetFlow)
let dnsServer = DNSServer(address: IPAddress(fromString: "198.18.0.1")!, port: NEKit.Port(port: 53))
let resolver = UDPDNSResolver(address: IPAddress(fromString: "8.8.8.8")!, port: NEKit.Port(port: 53))
dnsServer.registerResolver(resolver)
self.interface.register(stack: dnsServer)
from nekit.
请参考 https://forums.developer.apple.com/thread/35027 ,这里是最权威的回答了
from nekit.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from nekit.
Related Issues (20)
- 使用NEKit能否完全使用tcp/udp的方式去代理呢? HOT 2
- nekit vpn打开之后 微信,qq 这种基于socket做的通信类app都无法访问
- 请问支持V2ray vmess协议吗? HOT 3
- 我设置全局走代理,ios12正常,ios13偶尔不走代理
- 编译报错(Module 'NEKit' was created for incompatible target x86_64-apple-macos10.11:) HOT 2
- support SSR? HOT 1
- mayday mayday telegram连接的问题 HOT 2
- is there any plan to support AES256GCM?
- xcode11.2.1 telegram socks5代理连接失败 HOT 3
- Question HOT 2
- How to support aes-256-gcm? HOT 2
- xcrun: error: unable to find utility "xcodebuild", not a developer tool or in PATH HOT 1
- 新手问一下怎么打包带CHACHA20POLY1305的项目 HOT 1
- 求助HTTPS代理怎么设置呢? HOT 29
- 你好,我试用NEkit 软件在后台经常遇到Crashed HOT 11
- 这个框架能链接V2ray吗
- Fails when `Building scheme "iOS Framework" in CocoaAsyncSocket.xcodeproj` HOT 5
- 升级到最新的NEKit ,iOS和MacOS上连接正常的SS都是先连接成功然后过几秒就断开 HOT 6
- 连接几次后,打开网络或者请求VPN就会断开,请问什么原因 HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nekit.