Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having trouble grabbing a device's hostname using its IP address on Android

 
Daniel Crawford
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried ... but it isn't able to resolve the host name and instead returns the ip address. I know for a fact that the ip is on my network(the ip is my android device) I get the same result if I run the same code on my PC.

Most solutions I find require the Android device to be rooted, which isn't an option. I can't seem to find another way to find the host name with Java on Android.

I'm thinking there might be a way to find the hostname if I used JNetPCap but it doesn't seem like it works too well on android. (I have found many accounts of people who use JNetPCap on Android that need root perms)

I've decompiled the apk for some apps that seem capable of getting this information (Fing, Wifi Inspector) and am in the middle of reading through all their files. Unfortunately, I'm very slow and am having a hard time figuring out how these apps are capable of gathering this information.
There is also an open source app that grabs information about devices on your network that I've been looking through, but this app isn't capable of finding the hostname of a device.

Anyways, I'm having trouble finding an answer to my problem. I've read through many posts online that have similar problems. I've asked similar questions on a few other forums including stackoverflow. So far, I haven't found a working solution to grab the hostname of a device using its IP.

Any ideas or advice you could give me? I will continue trying to work on this problem... I'm just hoping there is someone here who could help me figure out how to solve this problem.
All replies are much appreciated!
 
L Foster
Ranch Hand
Posts: 185
10
Android Java Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. Sorry I cannot simply offer a solution. However, I did check, and found the exact same thing you did. This happened regardless of whether I looked up my IP address using software, or hardcoded one I found in the DHCP table of my router (they differed, BTW).

However, there is a post out on Stack Overflow that allowed me to get the same host name for my device, as was presented in the DHCP table.

http://stackoverflow.com/questions/21898456/get-android-wifi-net-hostname-from-code

This code came with a disclaimer, about the API itself. This is not using the IP address, but rather some environment variable. I hope it helps.
 
Daniel Crawford
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
L Foster wrote:Hello. Sorry I cannot simply offer a solution. However, I did check, and found the exact same thing you did. This happened regardless of whether I looked up my IP address using software, or hardcoded one I found in the DHCP table of my router (they differed, BTW).

However, there is a post out on Stack Overflow that allowed me to get the same host name for my device, as was presented in the DHCP table.

http://stackoverflow.com/questions/21898456/get-android-wifi-net-hostname-from-code

This code came with a disclaimer, about the API itself. This is not using the IP address, but rather some environment variable. I hope it helps.


This is pretty neat. Thanks for the share!

Only... this gets the hostname of your device. What I am trying to do is get the hostname of other devices connected to your network.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic