Created
August 6, 2019 01:15
-
-
Save MadeBugs/dd3368f9bb8213ca6ef072bc8bc42eb8 to your computer and use it in GitHub Desktop.
判断当前网络是否连接了VPN,用于抓包什么的
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var isConnectedToVpn: Bool { | |
if let settings = CFNetworkCopySystemProxySettings()?.takeRetainedValue() as? Dictionary<String, Any>, | |
let scopes = settings["__SCOPED__"] as? [String:Any] { | |
for (key, _) in scopes { | |
if key.contains("tap") || key.contains("tun") || key.contains("ppp") || key.contains("ipsec") || key.contains("ipsec0") { | |
return true | |
} | |
} | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment