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 0.0.0.0 0.0.0.0 0x00001002sit0 DOWN 0.0.0.0 0.0.0.0 0x00000080ip6tnl0 DOWN 0.0.0.0 0.0.0.0 0x00000080gannet0 DOWN 0.0.0.0 0.0.0.0 0x00001082rmnet0 UP 112.79.87.220 255.0.0.0 0x000000c1rmnet1 DOWN 0.0.0.0 0.0.0.0 0x00000080rmnet2 DOWN 0.0.0.0 0.0.0.0 0x00000080
“adb shell ifconfig rmnet0”
rmnet0: ip 112.79.87.220 mask 255.0.0.0 flags [up running]