Last active
September 6, 2018 03:22
-
-
Save omiq/e0a27061b5c19d56e02af182455f0057 to your computer and use it in GitHub Desktop.
Scan local area network and get info about devices (currently highlights Pi devices) * Run with Sudo
This file contains hidden or 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
import sys | |
import nmap | |
import time | |
nm = nmap.PortScanner() | |
nm.scan('10.0.1.0/24', '22') | |
# clear screen | |
sys.stdout.write(u"\u001b[2J\u001b[0;0H") | |
sys.stdout.flush() | |
time.sleep(0.2) | |
# iterate over the hosts on the network | |
for host in sorted(nm.all_hosts()): | |
# blank if not Pi | |
vendor = "" | |
if len(nm[host]['vendor']) > 0: | |
# attempt to get mac address | |
try: | |
mac = nm[host]['addresses']['mac'] | |
except: | |
mac = "" | |
vendor = tuple(nm[host]['vendor'].values()) | |
if str(vendor).find('Raspberry') > 0: | |
vendor = "Pi!" | |
print(u"\u001b[37m" + "{} ({}) {}\u001b[0m".format(nm[host].hostname(), host, mac)) | |
else: | |
vendor = "" | |
print(u"\u001b[0m" + "{} ({}) {}\u001b[0m".format(nm[host].hostname(), host, mac)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment