Created
August 28, 2018 21:26
-
-
Save omiq/2f3edf2624a72e89ba3a3a009a673a21 to your computer and use it in GitHub Desktop.
Scan your local network for the host, IP and mac address, and detect Raspberry Pi
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
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