如何选择要在我的Cocoa应用程序中使用的网络接口 [英] How to select the network interface to use in my Cocoa app

查看:112
本文介绍了如何选择要在我的Cocoa应用程序中使用的网络接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在不同的网络上运行测试。我可以在两个WiFi连接之间切换,但我需要知道如何在以太网电缆连接的WiFi上测试。

I am trying to run a test on different networks. I am able to switch between two WiFi connections but I need to know how can I run a test on WiFi with Ethernet cable connected.

基本上,我需要运行ping测试以检查机器上的所有网络是否工作正常。连接以太网端口时,它始终在以太网上运行ping。我想在不同的网络之间切换。我可以这样做的WiFi连接没有以太网连接。

So basically, I need to run the ping test to check if all the networks on the machine works well or not. With Ethernet port connected, it always run the ping on the Ethernet. I wanted to switch between different networks. I am able to do this on WiFi connections without Ethernet connected.

推荐答案

您可能需要考虑的另一个选择是使用系统配置框架。

Another alternative you might want to consider is to make use of the System Configuration framework.

您可以使用 SCNetworkSetSetCurrent (更改网络集,启用了仅启用以太网功能的另一个设置)。

You can use functions like "SCNetworkSetSetCurrent" (to change network sets from one where only WiFi is enabled to another set where only Ethernet is enabled).

此外,如果您不打算向普通大众或通过应用商店发布此应用, do Terminal / UNIX命令行类似 sudo ifconfig 以在测试之间上下移动特定界面(例如 en0 ) 。

Also, if you're not going to release this app to the general public or through the app store, you can do Terminal/UNIX command line things like "sudo ifconfig" to take a specific interface (e.g. "en0") up or down between tests.

这篇关于如何选择要在我的Cocoa应用程序中使用的网络接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆