数据包隧道提供商 IOS 中的动态 DNS

Posted

技术标签:

【中文标题】数据包隧道提供商 IOS 中的动态 DNS【英文标题】:Dynamic DNS in packet tunnel provider IOS 【发布时间】:2021-02-23 09:31:52 【问题描述】:

我的应用程序包含使用数据包隧道提供程序的 *** 配置 在 tunnelNetworkSettings.dnsSettings 上设置隧道时,我们将 8.8.8.8 有任何优雅且合法的方法可以通过设备使用的 dns(wifi、4g 等)将其更改为动态的

让 dnsSettings = NEDNSSettings(servers:[8.8.8.8])

tunnelNetworkSettings.dnsSettings = dnsSettings

【问题讨论】:

【参考方案1】:

您可以使用此代码获取系统 DNS 服务器

static func getSystemDnsList() -> ([String]/*IPV4*/, [String]/*IPV6*/) 
        var dnsListIPV4 = [String]()
        var dnsListIPV6 = [String]()
            let structSize = MemoryLayout<__res_9_state>.size
            let res = UnsafeMutablePointer<__res_9_state>.allocate(capacity: structSize)
            let result = res_9_ninit(res)
            if result == 0 
                let structSize = MemoryLayout<res_9_sockaddr_union>.size
                let capacity = Int(res.pointee.nscount) * structSize

                let addrUnion = UnsafeMutablePointer<res_9_sockaddr_union>.allocate(capacity: capacity)
                res_9_getservers(res, addrUnion, res.pointee.nscount)

                for i in 0..<Int(res.pointee.nscount) 
                    if addrUnion[i].sin.sin_family == AF_INET 
                        let ip = UnsafeMutablePointer<Int8>.allocate(capacity: Int(INET_ADDRSTRLEN))

                        var ipStringObject : String?
                        if let ipStr = inet_ntop(AF_INET, &(addrUnion[i].sin.sin_addr), ip, socklen_t(INET_ADDRSTRLEN)) 
                            ipStringObject = String(utf8String: ipStr)
                        

                        var portStringObject : String?
                        let port = nTohs(addrUnion[i].sin.sin_port)
                        portStringObject = String(format: "%d", port)

                        if let ip = ipStringObject 
                            dnsListIPV4.append(ip)
                        
                     else if addrUnion[i].sin6.sin6_family == AF_INET6 
                        let ip = UnsafeMutablePointer<Int8>.allocate(capacity: Int(INET6_ADDRSTRLEN))

                        var ipStringObject : String?
                        if let ipStr = inet_ntop(AF_INET6, &(addrUnion[i].sin6.sin6_addr), ip, socklen_t(INET6_ADDRSTRLEN)) 
                            ipStringObject = String(utf8String: ipStr)
                        

                        var portStringObject : String?
                        let port = nTohs(addrUnion[i].sin6.sin6_port)
                        portStringObject = String(format: "%d", port)

                        if let ip = ipStringObject 
                            dnsListIPV6.append(ip)
                        
                    
                

                res_9_nclose(res)
                free(res)
            

            return (dnsListIPV4, dnsListIPV6)
        

【讨论】:

以上是关于数据包隧道提供商 IOS 中的动态 DNS的主要内容,如果未能解决你的问题,请参考以下文章

2016.6.17 kali Linux 隧道工具

udp 隧道中的数据包丢弃和拆分

DNS隧道小结

VPN三层隧道协议GRE IPsec

GRE OVER IPSEC的数据包的IP地址是如何封装的

虚拟隧道协议