在android中获取网关ip地址
如何获取网关 IP 详细信息,可以选择使用 wifimanager,但是。如果没有 wify,当使用 USB 网络共享连接时,如何在 Android 设备中查找网关、DNS 和其他详细信息。
How to get gateway IP details , There is option using wifimanager but. If there is no wify how to find gateway,dns and other details in android device when connected using usb tethering.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
安装终端模拟器应用程序,然后从命令提示符运行 iproute 来查看路由表。不需要root权限。我不知道如何获取 DNS 服务器。没有
/etc/resolv.conf
文件。您可以尝试nslookup www.google.com
并查看它为您的服务器报告的内容,但在我的手机上它报告0.0.0.0
,这没有太大帮助。Install terminal emulator app, then to see routing table run
iproute
from the command prompt. Does not require root permissions. I don't know how to get the DNS server. There's no/etc/resolv.conf
file. You can trynslookup www.google.com
and see what it reports for your server, but on my phone it reports0.0.0.0
which isn't too helpful.该解决方案将为您提供网络参数。查看此解决方案
This solution will give you the Network parameters. Check out this solution
我在android 2.3.4上使用cyanogenmod 7.2,然后打开终端模拟器并输入:
I'm using cyanogenmod 7.2 on android 2.3.4, then just open terminal emulator and type:
在 Android 7 上可以正常工作:
输出将是:
8.8.8.8 通过网关...
On Android 7 works it:
output will be:
8.8.8.8 via gateway...
我想将此答案作为更新发布给最新 Android 版本 (CM11/KitKat/4.4.4) 的用户。我还没有使用 TouchWiz 或旧版 Android 版本测试过这些,所以 YMMV。
以下命令可以在所有常用位置(ADB、终端仿真器、shell 脚本、Tasker)运行。
列出所有可用属性:
获取 WiFi 接口:
WiFi 属性:
无论当时 WiFi 是否实际连接,上述命令都会输出信息。
使用以下任一方法来检查 wlan0 是否已打开:
使用以下任一方法来获取 wlan0 的 IP 地址(仅当它已连接时):
为了彻底起见,获取您的公共互联网-面对IP地址,您将需要使用外部服务。获取您的公共 IP:
获取您的公共主机名:
或者直接从您的 IP 地址获取您的公共主机名:
注意:上述
awk
命令看起来过于复杂,只是因为它能够处理各种版本的输出nslookup
。 Android 包含最小版本的nslookup
作为busybox
的一部分,但也有一个独立版本(通常包含在dnsutils
中)。I wanted to post this answer as an update for users of more recent Android builds (CM11/KitKat/4.4.4). I have not tested any of this with TouchWiz or older Android releases so YMMV.
The following commands can be run in all the usual places (ADB, Terminal Emulator, shell scripts, Tasker).
List all available properties:
Get WiFi interface:
WiFi properties:
The above commands will output information regardless of whether WiFi is actually connected at the time.
Use either of the following to check whether wlan0 is on or not:
Use either of the following to get the IP address of wlan0 (only if it is connected):
Just for thoroughness, to get your public Internet-facing IP address, you're going to want to use an external service. To obtain your public IP:
To obtain your public hostname:
Or to obtain your public hostname directly from your IP address:
Note: The aforementioned
awk
command seems overly complicated only because is able to handle output from various versions ofnslookup
. Android includes a minimal version ofnslookup
as part ofbusybox
but there is a standalone version as well (often included indnsutils
).前往终端
Go to terminal
请尝试以下操作:
Try the following:
DNS 服务器是通过
更新获得的:从 Android Nougat 7.x 开始,ifconfig 存在,而 netcfg 消失了。所以ifconfig可以用来查找IP和网络掩码。
DNS server is obtained via
UPDATE: as of Android Nougat 7.x, ifconfig is present, and netcfg is gone. So ifconfig can be used to find the IP and netmask.
这似乎对我来说很有效。在 Touchwiz 5.1、LineageOS 7.1 和 CyanogenMod 11 上进行测试。
输出类似于以下内容:
This seems to work well for me. Tested on Touchwiz 5.1, LineageOS 7.1, and CyanogenMod 11.
Gives output similar to this: