用于在 Android 应用程序中配置静态 IP 地址的 API
是否可以在应用程序中设置 Android 接口的 IP 地址?
我可以使用 java.net.NetworkInterface 查询可用接口及其当前地址,但这不提供更改这些接口的工具。我是不是错过了什么地方,或者这是不允许的?
我希望能够使我的应用程序在运行时在“现成的”设备上更改或添加一个或多个现有接口的别名。 (2.1/2.2)。理想情况下,我想对 IPv4 和 IPv6 地址。
Is it possible to set the IP address of an interface in Android within an application?
I can query the available interfaces and their current addresses using java.net.NetworkInterface
, but this doesn't provide a facility to change these. Did I just miss something somewhere, or is it not allowed?
I was hoping to be able to make my application either change or add an alias to one or more of the existing interfaces at runtime on an "off the shelf" device. (2.1/2.2). Ideally I'd like to do this for both IPv4 and IPv6 addresses.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Settings.System
包含几个可用于此目的的标志:WIFI_USE_STATIC_IP
WIFI_STATIC_IP
WIFI_STATIC_NETMASK
WIFI_STATIC_GATEWAY
WIFI_STATIC_DNS1
和WIFI_STATIC_DNS2
您还需要
android.permission.WRITE_SETTINGS
为您的申请声明的许可。然后在您的活动中:
如果您想更改运营商的 3G/4G 等接口的 IP 地址,我认为这是不可能的 - 因为它连接到运营商并使用他们的 DHCP/安全性来使您能够连接和使用他们的服务(有点像在未经 ISP 同意的情况下更改电缆调制解调器的外部 IP)。
Settings.System
includes several flags you can use for this:WIFI_USE_STATIC_IP
WIFI_STATIC_IP
WIFI_STATIC_NETMASK
WIFI_STATIC_GATEWAY
WIFI_STATIC_DNS1
andWIFI_STATIC_DNS2
You'll also need the
android.permission.WRITE_SETTINGS
permission declared for your application.Then in your activity:
If you want to change the IP address of the carrier's 3G/4G,etc interface, I do not believe this is possible - as it is connected to the carrier and uses their DHCP/security for enabling you to connect and use their services (sort of like changing the external IP of your cable modem without the consent of your ISP).