ios 我可以编辑 iPad 的主机文件吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4783923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:39:10  来源:igfitidea点击:

Can I edit an iPad's host file?

ipadfileiosedithosts

提问by Ahmed Nuaman

I doubt this is possible without extensive jail-breaking, but is it at all possible to edit the iPad's (or any iOS device's) hosts file?

我怀疑这在没有大量越狱的情况下是可能的,但是是否有可能编辑 iPad(或任何 iOS 设备)的主机文件?

采纳答案by Jonathan.

No. Apps can only modify files within the documents directory, within their own sandbox. This is for security, and ease of installing/uninstalling. So you could only do this on a jailbroken device.

不能。应用程序只能在自己的沙箱中修改文档目录中的文件。这是为了安全和易于安装/卸载。因此,您只能在越狱设备上执行此操作。

回答by tremoloqui

The previous answer is correct, but if the effect you are looking for is to redirect HTTP traffic for a domain to another IP there is a way.

前面的答案是正确的,但如果您正在寻找的效果是将域的 HTTP 流量重定向到另一个 IP,则有一种方法。

Since it technically is not answering your question, I have asked and answered the question here:

由于它在技术上没有回答您的问题,因此我在这里提出并回答了这个问题:

How can I redirect HTTP requests made from an iPad?

如何重定向从 iPad 发出的 HTTP 请求?

回答by holys

No, you can't change iPad's host file(without jailbreak), but can workaround.

不,您不能更改 iPad 的主机文件(没有越狱),但可以解决。

Here is my scenario:

这是我的场景:

  • Mac OS X, with IP 192.168.2.1, running a web app
  • iPad, the device you would like to test the web app
  • Charles(for Mac), enables HTTP proxy for your iPad
  • Mac OS X,带 IP 192.168.2.1,运行网络应用程序
  • iPad,您要测试 Web 应用程序的设备
  • Charles(for Mac), 为你的 iPad 启用 HTTP 代理

I am going to test the web app running in my Mac via iPad, but I can't access directly to it.

我将通过 iPad 测试在我的 Mac 中运行的网络应用程序,但我无法直接访问它。

The solution works for me:

解决方案对我有用:

  • Firstly, make sure that your server and iPad are in the same local network.
  • Then, set up Charles proxy, in the menu "Proxy > Proxy Settings...", fill in Port(mostly 8888) and toggle Enable transparent HTTP proxying.
  • 首先,确保您的服务器和 iPad 在同一个本地网络中。
  • 然后,设置Charles 代理,在菜单“代理> 代理设置...”中,填写Port(大部分8888)并切换Enable transparent HTTP proxying

enter image description here

在此处输入图片说明



  • Setup proxy setting in iPad.
  • 在 iPad 中设置代理设置。

enter image description here

在此处输入图片说明

Now you can visit your web app in iPad.

现在您可以在 iPad 中访问您的网络应用程序。

Of course you can use other proxy tools like Squidor Varnishin Linux, or fiddlerin Wondows.

当然你也可以使用其他的代理工具,如鱿鱼光油在Linux或小提琴手在WONDOWS。

回答by Erti-Chris Eelmaa

I needed the same functionality, and doing jailbreak is no-no. One solution is to host yourself DNS server (MaraDNS), go to your wifi settings in ipad/phone, and add your custom DNS server there.

我需要相同的功能,并且越狱是不行的。一种解决方案是托管自己的 DNS 服务器 ( MaraDNS),转到 ipad/手机中的 wifi 设置,然后在那里添加您的自定义 DNS 服务器。

The whole process took me only 10 minutes, and it works!

整个过程只花了我 10 分钟,而且很有效!

1) Download MaraDNS

1) 下载MaraDNS

2) Run mkSecretTxt.exeas administrator

2)mkSecretTxt.exe以管理员身份运行

3) Modify mararcfile, mine is:

3)修改mararc文件,我的是:

ipv4_bind_addresses = "put your public IP Here"
timestamp_type = 2
random_seed_file = "secret.txt"

csv2 = {}
csv2["Simple.Example.com."] = "example.configuration"

Add file called "example.configuration" into the same folder where run_maradns.batis.

将名为“ example.configuration”的文件添加到同一个文件夹中run_maradns.bat

4) Edit your example.configuration file:

4) 编辑您的 example.configuration 文件:

Simple.Example.com. 10.10.13.13 ~

5) Disable all Firewalls (convenience)

5)禁用所有防火墙(方便)

6) Run file "run_maradns.bat"

6) 运行文件“ run_maradns.bat

7) There should be no errors.

7) 应该没有错误。

8) Add your DNS server to list, as shown here: http://www.iphonehacks.com/2014/08/change-dns-iphone-ipad.html

8) 将您的 DNS 服务器添加到列表中,如下所示:http: //www.iphonehacks.com/2014/08/change-dns-iphone-ipad.html

9) Works!

9)作品!

回答by Payson Welch

The easiest way to do this is to run an iPad simulator using XCode and then add an entry in the hosts file (/etc/hosts) on the host system to point to your test site.

最简单的方法是使用 XCode 运行 iPad 模拟器,然后在主机系统的主机文件 (/etc/hosts) 中添加一个条目以指向您的测试站点。

回答by Apollo Clark

Yes, you can edit the iPad hosts file, but you need to be jailbroken. Once you've done that, download Cydia (app market), and get iFile. The hosts file is located within "/etc/hosts".

是的,您可以编辑 iPad hosts 文件,但您需要越狱。完成后,下载 Cydia(应用程序市场)并获取 iFile。主机文件位于“/etc/hosts”中。

回答by CosmicChild

I would imagine you could do it by setting up a transparent proxy, using something like charles and re-direct traffic that way

我想你可以通过设置透明代理来做到这一点,使用查尔斯之类的东西并以这种方式重定向流量

回答by tauanz

Workarond I use for development purposes:

我用于开发目的的解决方法:

  1. Create your own proxy server (One option would be: Squid on Linux).
  2. Set your hosts file with your domains.
  3. Set the proxy server on the IPAD/IPHONE and you can use with your hosts.
  1. 创建您自己的代理服务器(一种选择是:Linux 上的 Squid)。
  2. 使用您的域设置主机文件。
  3. 在 IPAD/IPHONE 上设置代理服务器,您可以与您的主机一起使用。

回答by Carlos Cap

I know it's been a while this has been posted, but with iOS 7.1, a few things have changed.

我知道这已经发布了一段时间,但是在 iOS 7.1 中,一些事情发生了变化。

So far, if you are developing an App, you MUST have a valid SSL certificate recognized by Apple, otherwise you will get an error message on you iDevice. No more self-signed certificates. See here a list:

到目前为止,如果您正在开发 App,您必须拥有 Apple 认可的有效 SSL 证书,否则您会在您的 iDevice 上收到错误消息。不再需要自签名证书。在这里看到一个列表:

http://support.apple.com/kb/ht5012

http://support.apple.com/kb/ht5012

Additionally, if you are here, it means that you are trying to make you iDevice resolve a name (to your https server), on a test or development environment.

此外,如果您在这里,则意味着您正在尝试让您的 iDevice 在测试或开发环境中解析名称(到您的 https 服务器)。

Instead of using squid, which is a great application, you could simply run a very basic DNS server like dnsmasq. It will use your hosts file as a first line of name resolution, so, you can basically fool your iDevice there, saying that www.blah.com is 192.168.10.10.

而不是使用鱿鱼,这是一个伟大的应用程序,你可以简单地运行像的dnsmasq一个非常基本的DNS服务器。它将使用您的主机文件作为名称解析的第一行,因此,您基本上可以在那里欺骗您的 iDevice,说 www.blah.com 是 192.168.10.10。

The configuration file is as simple as 3 to 4 lines, and you can even configure its internal DHCP server if you want.

配置文件就3到4行那么简单,如果你愿意,你甚至可以配置它的内部DHCP服务器。

Here is mine:

这是我的:

listen-address=192.168.10.35

监听地址=192.168.10.35

domain-needed

领域需要

bogus-priv

假隐私

no-dhcp-interface=eth0

no-dhcp-interface=eth0

local=/localnet/

本地=/本地网/

Of course you have to configure networking on your iDevice to use that DNS (192.168.10.35 in my case), or just start using DHCP from that server anyway, after properly configured.

当然,您必须在您的 iDevice 上配置网络以使用该 DNS(在我的情况下为 192.168.10.35),或者在正确配置后仍然从该服务器开始使用 DHCP。

Additionally, if dnsmasq cannot resolve the name internally, it uses your regular DNS server (like 8.8.8.8) to resolve it for you. VERY simple, elegant, and solved my problems with iDevice App installation in-house.

此外,如果 dnsmasq 无法在内部解析名称,它会使用您的常规 DNS 服务器(如 8.8.8.8)为您解析它。非常简单、优雅,并解决了我在内部安装 iDevice App 的问题。

By the way, solves many name resolution problems with regular macs (OS X) as well.

顺便说一下,它也解决了普通 mac (OS X) 的许多名称解析问题。

Now, my rant: bloody Apple. Making a device safe should not include castrating the operating system or the developers.

现在,我的咆哮:该死的苹果。确保设备安全不应包括阉割操作系统或开发人员。

回答by Savas

You can also make use of a proxy server on your iPhone or iPade via mobile internet (3G) by using a iPhone Mobile proxy generator:

您还可以使用 iPhone 移动代理生成器通过移动互联网 (3G) 在 iPhone 或 iPade 上使用代理服务器:

http://iphonesettings.net/mobileproxygenerator.php

http://iphonesettings.net/mobileproxygenerator.php

Just enter the apn of your carrier (with apn username/password if needed) and the proxy server you want to go through and tap Generate

只需输入您的运营商的 apn(如果需要,请输入 apn 用户名/密码)和您想要通过的代理服务器,然后点击生成