Skip to content

Instantly share code, notes, and snippets.

@scrivocodice
Last active March 16, 2026 22:01
Show Gist options
  • Select an option

  • Save scrivocodice/9b9047ee35a3c0e5880937a14807f690 to your computer and use it in GitHub Desktop.

Select an option

Save scrivocodice/9b9047ee35a3c0e5880937a14807f690 to your computer and use it in GitHub Desktop.
Scan neighbors network devices
#!/usr/bin/env python
"""List all hosts with their IP address on my subnet."""
import os
out = os.popen('ip neighbour show nud reachable').read().splitlines()
for i, line in enumerate(out, start=1):
ip = line.split(' ')[0]
h = os.popen(f'host {ip}').read()
hostname = h.split(' ')[-1]
print(f"{i:>3}: {hostname.strip()} ({ip})")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment