Archive for August, 2010

IP address of android phone using ADB

August 3, 2010

Few days back i was doing a project based on TCP sockets for android phone and repeatedly needed me to know the current IP address of the phone using ADB. It is as easy as a breeze, IP address can be determined by using just couple of shell commands.

Android phone can connect to internet using one of the multiple available interfaces,  for example  it can connect over cellular interface,wifi,bluetooth, wimax etc ( haven’t seen any other interface till now, if you see any other leave a comment about it ). When phone connects using an interface , IP address will be assigned to it.  In order to know the available network interfaces on the android phone below command can be used :

“adb shell netcfg”

Output of the above command will be

usb0     DOWN         0x00001002
sit0     DOWN         0x00000080
ip6tnl0  DOWN         0x00000080
gannet0  DOWN         0x00001082
rmnet0   UP       0x000000c1
rmnet1   DOWN         0x00000080
rmnet2   DOWN         0x00000080

Current network interface used by the phone will have the IP address , in the above output rmnet0 is used to connect to internet ( UP signifies link is up and active in the above output ) . You can use the ifconfig command with the network configuration name to get the details :
“adb shell ifconfig rmnet0”

Output will look like this :
rmnet0: ip mask flags [up running]

Leave a comment if you know of  find a better way of doing the same.