4

i am using the code of this link How to get IP address of the device from code? but getting ip address different than from my machine....how can i get the ip address of my machine on android emulator..

thanks in advance

Community
  • 1
  • 1
Ashish Tamrakar
  • 810
  • 10
  • 24

2 Answers2

4

Check this out if you want to access host machine.

Another solution is to run this on shell

$ adb shell am start -a android.intent.action.WEB_SEARCH -e query "what is my ip"

it will display your system IP

Juri
  • 32,424
  • 20
  • 102
  • 136
Aswin Anand
  • 242
  • 1
  • 11
  • Thanks Aswin for help.....could you provide me some sample to run this code on shell though java – Ashish Tamrakar Apr 12 '12 at 07:42
  • http://stackoverflow.com/questions/6882248/solved-running-shell-commands-though-java-code-on-android check this question – Aswin Anand Apr 12 '12 at 07:52
  • Ashwin please explore me what is android.intent.action.WEB_SEARCH here,should i have to modify that for my pc or not? – Ashish Tamrakar Apr 12 '12 at 09:46
  • Actually it will start intent with web search on query and it give you will your ip on google search. It will only useful for you to see the ip. Check this out, http://www.domaintools.com/research/my-ip/myip.xml Parse it and get your IP – Aswin Anand Apr 12 '12 at 10:38
  • this link is showing different ip address than of my ipconfig.....will you explore me this please – Ashish Tamrakar Apr 12 '12 at 13:30
0

import the package java.net;

and write the code,

try {
InetAddress thisIp =InetAddress.getLocalHost();
System.out.println("IP:"+thisIp.getHostAddress());
}
catch(Exception e) {
e.printStackTrace();
}
Neetesh
  • 917
  • 1
  • 6
  • 16
  • 1
    Thanks for help sir,but it is returning the ip address of the andorid emulator as it creates its own local network when run on a single machine,i want the ip address of my pc on android emulator...please help – Ashish Tamrakar Apr 12 '12 at 06:49