53

I need to fetch the IPaddress assigned by the operator after a successful 3G or LTE data call.

$adb shell netcfg >> doesnt have the assigned IP address.

I tried adb shell dumpsys and grep ip address, but in vain. Any help/pointers?

tomrozb
  • 25,773
  • 31
  • 101
  • 122
user1787049
  • 531
  • 1
  • 4
  • 3

13 Answers13

73

Try this command, it will help you to get ipaddress

adb shell ifconfig tiwlan0

tiwlan0 is the name of the wi-fi network interface on the device. This is generic command for getting ipaddress,

 adb shell netcfg

It will output like this

usb0     DOWN  0.0.0.0         0.0.0.0         0×00001002
sit0     DOWN  0.0.0.0         0.0.0.0         0×00000080
ip6tnl0  DOWN  0.0.0.0         0.0.0.0         0×00000080
gannet0  DOWN  0.0.0.0         0.0.0.0         0×00001082
rmnet0   UP    112.79.87.220   255.0.0.0       0x000000c1
rmnet1   DOWN  0.0.0.0         0.0.0.0         0×00000080
rmnet2   DOWN  0.0.0.0         0.0.0.0         0×00000080
Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
RajeshVijayakumar
  • 10,281
  • 11
  • 57
  • 84
26

Try:

adb shell ip addr show rmnet0

It will return something like that:

3: rmnet0: <UP,LOWER_UP> mtu 1500 qdisc htb state UNKNOWN qlen 1000
    link/[530]
    inet 172.22.1.100/29 scope global rmnet0
    inet6 fc01:abab:cdcd:efe0:8099:af3f:2af2:8bc/64 scope global dynamic
       valid_lft forever preferred_lft forever
    inet6 fe80::8099:af3f:2af2:8bc/64 scope link
       valid_lft forever preferred_lft forever 

This part is your IPV4 assigned by the operator

inet 172.22.1.100

This part is your IPV6 assigned by the operator

inet6 fc01:abab:cdcd:efe0:8099:af3f:2af2:8bc

Rene Barbosa
  • 2,867
  • 1
  • 13
  • 8
  • 3
    I think that everybody should start using `ip addr show ` because the `ifconfig` way is deprecated on recent linux systems and I noticed that `ifconfig` behaviour on a Lollipop Nexus 5 and Marshmallow Nexus 5X was different for `ifconfig` and `netcfg`, so `ip addr show` way was the only way I could get both working predictably. – aignas Feb 12 '16 at 12:34
  • should be accepted. 1. ifconfig not available (Cyanogen 13, Nexus 5). 2. netcfg needs root. use ip command, it's part of 'iproute2' – vigilancer Aug 21 '16 at 14:19
  • This works. ipconfig isn't available (s6 edge, stock OS) and netcfg cannot be recognized. It is probably root only as vigilancer said. – Zoe Jul 18 '17 at 14:53
  • Just `adb shell ip address show` shows all interfaces by default on Android 8. – Ciro Santilli OurBigBook.com Oct 20 '17 at 14:08
19

Try this command for Version <= Marshmallow,

adb devices

List of devices attached 38ccdc87 device

adb tcpip 5555

restarting in TCP mode port: 5555

adb shell ip addr show wlan0

24: wlan0: mtu 1500 qdisc mq state UP qlen 1000 link/ether ac:c1:ee:6b:22:f1 brd ff:ff:ff:ff:ff:ff inet 192.168.0.18/24 brd 192.168.0.255 scope global wlan0 valid_lft forever preferred_lft forever inet6 fd01::1d45:6b7a:a3b:5f4d/64 scope global temporary dynamic valid_lft 287sec preferred_lft 287sec inet6 fd01::aec1:eeff:fe6b:22f1/64 scope global dynamic valid_lft 287sec preferred_lft 287sec inet6 fe80::aec1:eeff:fe6b:22f1/64 scope link valid_lft forever preferred_lft forever

To connect to your device run this

adb connect 192.168.0.18

connected to 192.168.0.18:5555

Make sure you have adb inside this location android-sdk\platform-tools

Manish Singh Rana
  • 822
  • 1
  • 13
  • 26
  • 1
    If `adb tcpip [port not 5555]` connecting to the Ip alone will not work. A port has to be supplied if it isn't 5555 – Zoe Jul 18 '17 at 14:55
  • 2
    No need to connect adb via wifi, can also use in USB mode. Also, you don't want show wlan0 but simply ```adb shell ip -o a``` – Cornelius Roemer Dec 27 '19 at 14:38
17

According to comments: netcfg was removed in Android 6

Try

adb shell netcfg

Or

adb shell <device here or leave out if one device>
shell@android:/ $netcfg
Ravindranath Akila
  • 209
  • 3
  • 35
  • 45
  • 1
    With this I get `error: device not found` . `su` followed by `netcfg` worked for me – Atul Jun 02 '16 at 06:09
12

You can get the device ip address by this way:

adb shell ip route > addrs.txt
#Case 1:Nexus 7
#192.168.88.0/23 dev wlan0  proto kernel  scope link  src 192.168.89.48

#Case 2: Smartsian T1,Huawei C8813
#default via 192.168.88.1 dev eth0  metric 30
#8.8.8.8 via 192.168.88.1 dev eth0  metric 30
#114.114.114.114 via 192.168.88.1 dev eth0  metric 30
#192.168.88.0/23 dev eth0  proto kernel  scope link  src 192.168.89.152 metric 30
#192.168.88.1 dev eth0  scope link  metric 30

ip_addrs=$(awk {'if( NF >=9){print $9;}'} addrs.txt)

echo "the device ip address is $ip_addrs"
Folyd
  • 1,148
  • 1
  • 16
  • 20
12

You can try this command:

adb shell ip addr show rmnet0  | grep 'inet ' | cut -d ' ' -f 6 | cut -d / -f 1

It will return your IPV4 assigned by the operator

172.22.1.215

Note:

rmnet0 should be replaced with your interface my case was rmnet0 usually is eth0.

If u want to get the list of interfaces use this command:

ip link show

You will get something like this:

1: lo:  mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc mq state UP qlen 1000
    link/ether b8:ac:6f:65:31:e5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.5/24 brd 192.168.1.255 scope global eth0
    inet6 fe80::baac:6fff:fe65:31e5/64 scope link 
       valid_lft forever preferred_lft forever
3: wlan0:  mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 00:21:6a:ca:9b:10 brd ff:ff:ff:ff:ff:ff
4: pan0:  mtu 1500 qdisc noop state DOWN 
    link/ether 92:0a:e7:31:e0:83 brd ff:ff:ff:ff:ff:ff
5: vmnet1:  mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:50:56:c0:00:01 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.1/24 brd 192.168.121.255 scope global vmnet1
    inet6 fe80::250:56ff:fec0:1/64 scope link 
       valid_lft forever preferred_lft forever
6: vmnet8:  mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:50:56:c0:00:08 brd ff:ff:ff:ff:ff:ff
    inet 192.168.179.1/24 brd 192.168.179.255 scope global vmnet8
    inet6 fe80::250:56ff:fec0:8/64 scope link 
       valid_lft forever preferred_lft forever

Where usually,

  • lo – Loopback interface.
  • eth0 – Your first Ethernet network interface on Linux.
  • wlan0 – Wireless network interface in Linux.
Teocci
  • 7,189
  • 1
  • 50
  • 48
4

You also can try this:

Step 1: adb shell Step 2: ip -f inet addr show wlan0

Elnaz
  • 476
  • 1
  • 5
  • 7
3

adb shell ip addr > ippdetails.txt This will get all list of ip's assigned to devices.

NitZRobotKoder
  • 1,046
  • 8
  • 44
  • 74
3

To get all IPs (WIFI and data SIM) even on a non-rooted phone in 2019 use:

adb shell ip -o a

The output looks like:

1: lo    inet 127.0.0.1/8 scope host lo\       valid_lft forever preferred_lft forever
1: lo    inet6 ::1/128 scope host \       valid_lft forever preferred_lft forever
3: dummy0    inet6 fe80::489c:2ff:fe4a:00005/64 scope link \       valid_lft forever preferred_lft forever
11: rmnet_data1    inet6 fe80::735d:50fb:2e2:0000/64 scope link \       valid_lft forever preferred_lft forever
21: r_rmnet_data0    inet6 fe80::e38:ce2a:523a:0000/64 scope link \       valid_lft forever preferred_lft forever
30: wlan0    inet 192.168.178.0/24 brd 192.168.178.255 scope global wlan0\       valid_lft forever preferred_lft forever
30: wlan0    inet6 fe80::c2ee:fbff:fe4a:0000/64 scope link \       valid_lft forever preferred_lft forever

You can connect either through adb shell or run the command ip -o a directly in a terminal emulator. Again, no root required.

Cornelius Roemer
  • 3,772
  • 1
  • 24
  • 55
2

download this app from here it will help you to rum all commands. I have run netcfg and it gives the result as attached in screen.

output screen

Sher Ali
  • 5,513
  • 2
  • 27
  • 29
  • 1
    1) netcfg is root only. 2) That app is just access to the adb shell. Doing `adb shell` is much easier than downloading the app – Zoe Jul 18 '17 at 14:54
2

For IP address- adb shell ifconfig under wlan0 Link encap:UNSPEC you will have your ip address written

androminor
  • 322
  • 1
  • 13
1
ip route | grep rmnet_data0 | cut -d" " -f1 | cut -d"/" -f1

Change rmnet_data0 to the desired nic, in my case, rmnet_data0 represents the data nic.

To get a list of the available nic's you can use ip route

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
0
  1. Connect device via USB and make sure debugging is working, then run:
adb tcpip 5555
adb connect `adb shell ip addr show wlan0  | grep 'inet ' | cut -d ' ' -f 6 | cut -d / -f 1`:5555
  1. Disconnect USB and proceed with wireless debugging.

  2. When you're done and want to switch back to USB debugging, run:

adb -s`adb shell ip addr show wlan0  | grep 'inet ' | cut -d ' ' -f 6 | cut -d / -f 1`:5555

note:

  • wlan0 – Wireless network interface in Linux.
Luciano Ribas
  • 309
  • 2
  • 4