有没有办法在iOS设备上以编程方式更改网络路由? [英] Is there a way to programmatically change network routes on an iOS device?

查看:92
本文介绍了有没有办法在iOS设备上以编程方式更改网络路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:我想让iOS设备连接到没有上游Internet连接但仍保留并使用其蜂窝数据连接的LAN.

Scenario: I want to have an iOS device connect to a LAN that has no upstream Internet connection, yet still retain and use its cellular data connection.

从理论上讲,我感到震惊的是,iOS wifi NIC和蜂窝数据NIC与PC中的双NIC足够相似,因此我应该能够设置路由,以便发送到192.168.的任何请求. 通过wifi连接,其他任何请求都通过蜂窝数据连接.

Theoretically, it strikes me that the iOS wifi NIC and the cellular data NIC are similar enough to dual NICs in a PC that I should be able to set up routing such that any request to, say, 192.168.. goes through the wifi connection, and any other request goes through the cellular data connection.

我进行了一项测试,以查看通过以下步骤将iOS设备连接到wifi时,两个NIC是否都处于活动状态.

I did a test to see if both NICs are active when the iOS device is connected to wifi by the following steps.

  1. 确保iPhone的wifi处于关闭状态,并且蜂窝数据连接良好.
  2. 断开我的wifi路由器的以太网电缆与电缆调制解调器的连接.
  3. 将我的iPhone连接到wifi路由器.
  4. 使用仅通过蜂窝数据连接的另一部iPhone来创建与朋友的单词游戏.
  5. 另一部iPhone完成第一步后,我的iPhone收到一条通知,通知您有新游戏可以玩.

这证实了尽管已连接了wifi NIC,但蜂窝数据连接确实仍然有效并且足以接收推送通知.

This confirmed that the cellular data connection was indeed alive and well enough to receive push notifications despite the wifi NIC's being connected.

问题变成了,那么应用程序可以通过编程方式连接到给定的wifi网络,将蜂窝数据网络设置为默认路由,并将任何请求路由到例如192.168.了吗?通过wifi网络?

The question becomes, then, can an app programmatically connect to a given wifi network, set the cellular data network to be the default route, and route any requests to, say, 192.168.. to go through the wifi network?

推荐答案

我知道这篇文章很旧,但是我碰巧在iOS上使用多个网络接口方面做了一些工作.

I know this post is old, but I happen to have done some work on using multiple network interfaces on iOS.

我的实验表明,通过主机名访问会导致iOS选择要使用的网络接口,并且如果主机无法解析,则不尝试任何其他接口.

My experiments showed that accessing via hostname results in iOS choosing the network interface it wants to use, and not trying any further interfaces if the host cannot be resolved.

如果您知道任何基于以太网/WiFi的网络的DNS服务器IP地址,则可以自己发送DNS请求,将主机名转换为IP地址并通过IP地址进行访问.然后,iOS将使用正确的界面.

If you know the DNS Server IP address for any Ethernet/WiFi based network, you can send a DNS request yourself, convert the hostname into an IP address and access via IP address. iOS will then use the correct interface.

我的猜测是,如果您可以通过两个连接访问私有类IP地址空间,那么您将无权指定应使用哪个网络接口.

My guess is, that if you have the private class IP address space accessible over both connections, there's probably nothing you can do to specify which network interface should be used.

这篇关于有没有办法在iOS设备上以编程方式更改网络路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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