Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Last active April 3, 2017 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinThoma/699ae445b8a08b5afd16f7d6f5e5d0f8 to your computer and use it in GitHub Desktop.
Save MartinThoma/699ae445b8a08b5afd16f7d6f5e5d0f8 to your computer and use it in GitHub Desktop.
#!/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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment