简体   繁体   English

使用可达性检查VPN状态

[英]Check For VPN Status Using Reachability

I'm using Reachability to check for Wifi connectivity in my app. 我正在使用可达性来检查应用程序中的Wifi连接。

When Wifi is available is it then possible to check what type of connectivity it is? 如果可以使用Wifi,则可以检查它是哪种类型的连接? eg I want to check if VPN is connected. 例如,我想检查VPN是否已连接。

I have been looking for it too. 我也一直在寻找它。 though i have not managed to find any direct way but some guys online suggested these indirect methods. 尽管我还没有找到任何直接方法,但是一些在线的人建议使用这些间接方法。 take a look if they might help! 看看他们是否有帮助!

  1. use the BSD system call getifaddrs() to get a list of all network interfaces and then check whether anything that looks like VPN (eg utun0) is present. 使用BSD系统调用getifaddrs()获取所有网络接口的列表,然后检查是否存在任何类似于VPN的内容(例如utun0)。

  2. If you know exactly to which VPN server users of your app will be connected then you can try to check what is current DNS server 如果您确切知道您的应用程序将与哪些VPN服务器用户连接,则可以尝试检查当前的DNS服务器

  3. You can get some flags for a current connection and connection changes in the reachability API. 您可以在当前可达性API中获得一些有关当前连接和连接更改的标志。 Most likely some combination of flags should let you know whether it's VPN or no. 很有可能标志的某种组合应该让您知道它是VPN还是否。

Do update here if u try these out and they work! 如果您尝试使用这些工具,它们可以在这里更新! or if u find an easier way. 或者,如果您找到更简单的方法。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM