Get gateway ip address in android

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

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.

回答1:

I'm using cyanogenmod 7.2 on android 2.3.4, then just open terminal emulator and type:

$ ip addr show $ ip route show 


回答2:

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:

getprop 

Get WiFi interface:

getprop wifi.interface 

WiFi properties:

getprop dhcp.wlan0.dns1 getprop dhcp.wlan0.dns2 getprop dhcp.wlan0.dns3 getprop dhcp.wlan0.dns4 getprop dhcp.wlan0.domain getprop dhcp.wlan0.gateway getprop dhcp.wlan0.ipaddress getprop dhcp.wlan0.mask 

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:

ifconfig wlan0  netcfg | awk '{if ($2=="UP" && $3 != "0.0.0.0/0") isup=1} END {if (! isup) exit 1}' 

Use either of the following to get the IP address of wlan0 (only if it is connected):

ifconfig wlan0 | awk '{print $3}'  netcfg | awk '/^wlan0/ {sub("(0\\.0\\.0\\.0)?/[0-9]*$", "", $3); print $3}' 

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:

wget -qO- 'http://ipecho.net/plain' 

To obtain your public hostname:

wget -qO- 'http://ifconfig.me/host' 

Or to obtain your public hostname directly from your IP address:

(nslookup "$(wget -qO- http://ipecho.net/plain)" | awk '/^Address 1: / { if ($NF != "0.0.0.0") {print $NF; exit}}; /name =/ {sub("\\.$", "", $NF); print $NF; exit}') 2>/dev/null 

Note: The aforementioned awk command seems overly complicated only because is able to handle output from various versions of nslookup. Android includes a minimal version of nslookup as part of busybox but there is a standalone version as well (often included in dnsutils).



回答3:

Go to terminal

$ adb -s UDID shell $ ip addr | grep inet  or $ netcfg | grep inet 


回答4:

On Android 7 works it:

 ip route get 8.8.8.8 

output will be: 8.8.8.8 via gateway...



回答5:

DNS server is obtained via

getprop net.dns1  

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.



回答6:

This solution will give you the Network parameters. Check out this solution



回答7:

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 try nslookup www.google.com and see what it reports for your server, but on my phone it reports 0.0.0.0 which isn't too helpful.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!