Last active
April 3, 2017 21:45
-
-
Save MartinThoma/699ae445b8a08b5afd16f7d6f5e5d0f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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