Skip to content

Instantly share code, notes, and snippets.

@omiq
Created August 28, 2018 21:26
Show Gist options
  • Save omiq/2f3edf2624a72e89ba3a3a009a673a21 to your computer and use it in GitHub Desktop.
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
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