diff options
author | coderick14 | 2017-06-14 15:54:40 +0530 |
---|---|---|
committer | coderick14 | 2017-06-14 15:54:40 +0530 |
commit | 57190d1a28b07668459c7da244f2e5d40bde1654 (patch) | |
tree | 2c9bbc6b6dc2e687e9136c4a6c0f7f1adb42dd96 | |
parent | bab1bd450b649bcb79d10cde62028e7e2eb6f39e (diff) | |
download | SBHS-2018-Rpi-57190d1a28b07668459c7da244f2e5d40bde1654.tar.gz SBHS-2018-Rpi-57190d1a28b07668459c7da244f2e5d40bde1654.tar.bz2 SBHS-2018-Rpi-57190d1a28b07668459c7da244f2e5d40bde1654.zip |
Add script to scan RPi's
-rw-r--r-- | new_cron_job.sh | 5 | ||||
-rw-r--r-- | sbhs_server/create_ip_map.py | 23 | ||||
-rw-r--r-- | sbhs_server/scan_rpis.sh | 11 |
3 files changed, 37 insertions, 2 deletions
diff --git a/new_cron_job.sh b/new_cron_job.sh index f757e20..aa55092 100644 --- a/new_cron_job.sh +++ b/new_cron_job.sh @@ -10,11 +10,12 @@ cd $DIR killall streamer source ../bin/activate #source ./bin/activate -python sbhs_server/scan_machines.py +#python sbhs_server/scan_machines.py +bash sbhs_server/scan_rpis.sh #python offline_reconnect.py python manage.py makemigrations python manage.py migrate -python manage.py initialize_machines +#python manage.py initialize_machines python manage.py generate_checksum touch index.wsgi python manage.py log_generator diff --git a/sbhs_server/create_ip_map.py b/sbhs_server/create_ip_map.py new file mode 100644 index 0000000..2964be0 --- /dev/null +++ b/sbhs_server/create_ip_map.py @@ -0,0 +1,23 @@ +import json + +pi_ip_map = {} +ipaddrs = [] + +with open("temp/ipaddrs.txt", "r") as filehandler: + ipaddrs = filehandler.readlines() + +ipaddrs = [ip.strip() for ip in ipaddrs] + +for ip in ipaddrs: + filename = "temp/" + ip + ".txt" + with open(filename, "r") as filehandler: + for line in filehandler: + try: + data = line.split('=') + pi_ip_map[data[0].strip()] = ip + except: + pass + +json_data = json.dumps(pi_ip_map, indent=2, separators=(',',':')) +with open("pi-ip.json", "w") as filehandler: + filehandler.write(json_data)
\ No newline at end of file diff --git a/sbhs_server/scan_rpis.sh b/sbhs_server/scan_rpis.sh new file mode 100644 index 0000000..3a1fd3c --- /dev/null +++ b/sbhs_server/scan_rpis.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +mkdir -p temp +nmap -n -sP 10.42.0.255/24 | grep -E -o "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])" | grep -v "10.42.0.1" > temp/ipaddrs.txt + +while read -r ip +do + curl -o temp/$ip.txt $ip/map_machine_ids.txt +done < "temp/ipaddrs.txt" + +python create_ip_map.py
\ No newline at end of file |