如何通过本地网络中的主机名查找IP地址?

时间:2016-05-30 12:12:43

标签: android linux shell unix networking

我希望通过本地网络中的IP Address找到hostname设备。市场上的许多应用都是这样做的。它同时提供IP Addresshostname,例如FingIP Tools等等。但我仍然无法从IP Address找到hostname

我可以在IP中使用hostnamedigarp命令找到ping ubuntu OS 14.04,请参阅以下命令:< BR />

dig @224.0.0.251 -p 5353 example.local

这个命令给出了这样的输出:

 ; <<>> 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

具体的ANSWER SECTION针对ip给了我hostname。 当我使用以下命令时:

arp -vn example.local

它给了我以下输出:

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

当我使用hostname

ping设备时

ping example.local

它还给了我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

但是当我在adb shell上执行上述命令时,找不到大部分命令。 android中没有arpdig。 当我使用hostname通过adb shell ping设备时,它会出现以下错误:

ping: unknown host example.local

但是当我通过ip设备ping通时,它成功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

以上内容在同一个网络中完成,但我仍未通过IP获取hostname(当我使用来自adb shell的相同命令时)。如何使用IPhostname设备的android上找到adb shell
有谁知道我做错了什么?

1 个答案:

答案 0 :(得分:0)

我们可以如下运行ping命令

ping hostname -f

,从括号中的输出中,我们可以看到机器的IP地址