Skip to content

Commit ac94696

Browse files
authored
Create rpi-dectector-1.py
1 parent f46b878 commit ac94696

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

rpi-dectector-1.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
import platform
3+
import re
4+
import nmap
5+
import json
6+
7+
8+
rpi_ip_list = []
9+
rpi_name_list = []
10+
11+
12+
def pi_search():
13+
print ('Searching for RPi')
14+
print ("---------------------------")
15+
16+
nm = nmap.PortScanner()
17+
nm.scan('192.168.1.0/24',arguments='-sP') #Note that I tested with -sP to save time
18+
for host in nm.all_hosts():
19+
#print(host + " "+nm[host].hostname())
20+
item = nm[host]['addresses']
21+
if nm[host].hostname() == 'raspberrypi' :
22+
print (nm[host].hostname(),item)
23+
24+
print ("---------------------------")
25+
26+
def run():
27+
pi_search()
28+
29+
if rpi_ip_list == []:
30+
pi_search()
31+
32+
def main():
33+
34+
if rpi_ip_list == []:
35+
print ('Running nmap')
36+
pi_search()
37+
print ("HOST_VARS")
38+
39+
40+
if __name__ == "__main__":
41+
main()

0 commit comments

Comments
 (0)