5

I want to find IP Address of device through their hostname in local network. Lots of applications in market do this. It gives both IP Address and hostname, like Fing , IP Tools and many more. But still I am unable to find IP Address from hostname.

I am able to find IP of hostname by using dig, arp and ping command in ubuntu OS 14.04 see following command:

dig @224.0.0.251 -p 5353 example.local

This command gives me output like this :

 ; <<>> DiG 9.9.5-3ubuntu0.8-Ubuntu <<>> @224.0.0.251 -p 5353 example.local
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56566
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;example.local.         IN  A

;; ANSWER SECTION:
example.local.      10  IN  A   192.168.0.142

;; Query time: 0 msec
;; SERVER: 192.168.0.142#5353(224.0.0.251)
;; WHEN: Mon May 30 17:01:06 IST 2016
;; MSG SIZE  rcvd: 47

That specific ANSWER SECTION gives me ip against hostname. also when I used following command :

arp -vn example.local

It gives me following output:

Entries: 4  Skipped: 4  Found: 0
example.local (192.168.0.142) -- no entry

Also when i ping device with their hostname

ping example.local

It also gives me IP Address:

PING example.local (192.168.0.142) 56(84) bytes of data.
64 bytes from 192.168.0.142: icmp_seq=1 ttl=64 time=0.033 ms
64 bytes from 192.168.0.142: icmp_seq=2 ttl=64 time=0.059 ms
64 bytes from 192.168.0.142: icmp_seq=3 ttl=64 time=0.045 ms
64 bytes from 192.168.0.142: icmp_seq=4 ttl=64 time=0.060 ms
64 bytes from 192.168.0.142: icmp_seq=5 ttl=64 time=0.069 ms

But When I am doing above commands on adb shell, most of the command are not found. arp and dig is not present in android. And when I ping device through adb shell with their hostname, It gives me following error:

ping: unknown host example.local

But when I ping through ip of device, It successfully ping:

$ ping 192.168.0.142                                         
PING 192.168.0.142 (192.168.0.142) 56(84) bytes of data.
64 bytes from 192.168.0.142: icmp_seq=1 ttl=64 time=263 ms
64 bytes from 192.168.0.142: icmp_seq=2 ttl=64 time=231 ms
64 bytes from 192.168.0.142: icmp_seq=3 ttl=64 time=1.82 ms
64 bytes from 192.168.0.142: icmp_seq=4 ttl=64 time=1.99 ms
64 bytes from 192.168.0.142: icmp_seq=5 ttl=64 time=122 ms
64 bytes from 192.168.0.142: icmp_seq=6 ttl=64 time=5.63 ms

Above things are done in same network, but still I am not getting IP through hostname(When I used same command from adb shell). How can I find IP through their hostname on android device using adb shell.
Does anyone know what I am doing wrong?

Mangesh Sambare
  • 594
  • 3
  • 23
  • 1
    You are using wrong host name in ping command "example.local" while using adb shell. Your device does not know that hostname. You need to tell your device that IP 192.168.0.142 belongs to Host: example.local. This can be achieved using DNS server configuration(pretty complex) or editing hosts file on device (root required on device) – Sangram Jadhav May 30 '16 at 12:35
  • I am newbie in android. How I can use DNS server configuration? – Mangesh Sambare May 30 '16 at 12:54
  • 1
    oh it is not related to android at all. you need to configure DNS server of your network which will say "example.local" has ip 192.168.0.142. But I am not sure why you need the ip address by hostname. If you can tell us the use case, probably we can help out with alternate solutions – Sangram Jadhav May 30 '16 at 13:07
  • If you are developing an app, you can use android java api [See](http://stackoverflow.com/questions/15788453/resolving-ip-address-of-a-hostname) – Sangram Jadhav May 30 '16 at 13:13
  • @SangramJadhav: Ya It is not related to android, but i want try DNS configuration. Could you please help me. How can I configure DNS Server on `example.local`. Please share me any link/procedure that can help me. My example.local system is linux base system who has lots of capability to run DNS server. please help me? – Mangesh Sambare May 30 '16 at 13:44
  • You are confusing target host with DNS server. You already have a DNS server that you use in your dig command at 224.0.0.251. You need your device to know about it. I do not know how the network is configured on device, but the standard way to inform a network entity of a DNS server during network configuration would be to include it's (ip) address in DHCP. – Peter K Oct 31 '18 at 10:03

1 Answers1

0

We can run ping command as below

ping hostname -f

and from the output in bracket we can see the IP address of the machine