Simple VPN
ServusJon opened this issue · comments
Jonathan Arnold commented
Hi! I found your VPN example and I tried to simplify it:
import UIKit
import NetworkExtension
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let manager = NEVPNManager.shared()
manager.loadFromPreferences { error in
let vpnhost = "test"
let p = NEVPNProtocolIKEv2()
p.username = "username"
p.localIdentifier = "username"
p.serverAddress = ""
p.remoteIdentifier = vpnhost
p.authenticationMethod = .none
p.useExtendedAuthentication = true
p.serverCertificateIssuerCommonName = vpnhost
p.disconnectOnSleep = false
let onDemandRule = NEOnDemandRuleEvaluateConnection()
onDemandRule.interfaceTypeMatch = .any
let evaluateRule = NEEvaluateConnectionRule(matchDomains: ["*.google.de", "*.google.com"], andAction: .connectIfNeeded)
// evaluateRule.useDNSServers = [""]
evaluateRule.probeURL = URL(string: "about:blank")
onDemandRule.connectionRules = [evaluateRule]
manager.localizedDescription = "My VPN"
manager.protocolConfiguration = p
manager.onDemandRules = [onDemandRule]
manager.isOnDemandEnabled = true
manager.isEnabled = true
manager.saveToPreferences { error in
guard error == nil else {
print("NEVPNManager.saveToPreferencesWithCompletionHandler failed: \(error!.localizedDescription)")
return
}
try! manager.connection.startVPNTunnel()
}
}
}
}
I want to redirect when google.de and google.com are loaded. I also don't want to use an actual vpn server. I don't get any errors currently and the sites are loading :-(
Any ideas?