Для обоих ответов: НЕ требуется nmap / НЕ требуется sudo.
$ arp
Основываясь на ответе ксенотеррацидов с ip neigh
и hosts
:
#!/usr/bin/env python
"""List all hosts with their IP adress of the current network."""
import os
out = os.popen('ip neigh').read().splitlines()
for i, line in enumerate(out, start=1):
ip = line.split(' ')[0]
h = os.popen('host {}'.format(ip)).read()
hostname = h.split(' ')[-1]
print("{:>3}: {} ({})".format(i, hostname.strip(), ip))
Скачать через
wget https://gist.githubusercontent.com/MartinThoma/699ae445b8a08b5afd16f7d6f5e5d0f8/raw/577fc32b57a7f9e66fdc9be60e7e498bbec7951a/neighbors.py