From 69215b7e4cdd91c88ca7f03c6abb569924366254 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Fri, 10 Feb 2017 12:43:24 +0100 Subject: [PATCH] Init commit --- home.db | Bin 0 -> 2048 bytes macLookup.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ readFileHandler.py | 23 +++++++++++++++++++++++ times.txt | 5 +++++ 4 files changed, 72 insertions(+) create mode 100644 home.db create mode 100755 macLookup.py create mode 100755 readFileHandler.py create mode 100755 times.txt diff --git a/home.db b/home.db new file mode 100644 index 0000000000000000000000000000000000000000..dde4fe63bbc210b1c36dd6d5ce9f34c59ae96fb9 GIT binary patch literal 2048 zcmWFz^vNtqRY=P(%1ta$FlJz3U}R))P*7lCU|@n`AO!}DK#~Q@22mhBA;83-`*8;^ zP!%Kd1_mG+1*0J_8UhrAfFC29xS}FsW=UdFPHIkKafyFkPG%kwi^)02)iK0XA;i(i z$5jELLL)CRH&vk|wW35vp(GQ?Ov}knEYXDI&36pU?%;N0c Osb!gY4*&R#K>z>|`6@>M literal 0 HcmV?d00001 diff --git a/macLookup.py b/macLookup.py new file mode 100755 index 0000000..ed9d625 --- /dev/null +++ b/macLookup.py @@ -0,0 +1,44 @@ +#!/usr/bin/python + +import subprocess +from time import time, sleep + +# Define the users to lookup +users = ['Elias', 'Kevin', 'Nora', 'Inge', 'Bazzinga'] +addr = ['38:ca:da:eb:3f:da', '2c:33:61:aa:e6:a9', 'cc:29:f5:b8:2d:a2', 'ac:5f:3e:28:2a:c0', 'f0:79:59:70:a4:a6'] + + +def whosHome(): + # Get the output of the command 'arp-scan -l' + arpOutput = subprocess.check_output("sudo arp-scan -l", shell=True).split('\n') + # Strip away first three lines and last 5 lines + arpOutput = arpOutput[2:-4] + + # Open file times.txt and read lines to 'logFile' + with open('/home/kevin/homeCheck/times.txt', 'r') as file: + logFile = file.readlines() + + i = 0 + # Go through each element in list 'addr' + for mac in addr: + # Then iterate through each line in arpOutput + for line in arpOutput: + line_mac = str(line.split('\t')[1]) + + # For each line we check after a matching mac addr + if (mac in line_mac): + logFile[i] = str(users[i]) + ':' + str(time()) + '\n' + # print mac + # print users[i] + # print str(i) + '\n' + # print logFile + + i+=1 + + # Write changes to file + with open('/home/kevin/homeCheck/times.txt', 'w') as file: + file.writelines(logFile) + print logFile + + +whosHome() diff --git a/readFileHandler.py b/readFileHandler.py new file mode 100755 index 0000000..d166047 --- /dev/null +++ b/readFileHandler.py @@ -0,0 +1,23 @@ +from socket import * + +# Define the socket communicating will transfered +serverSocket = socket(AF_INET, SOCK_DGRAM) +serverSocket.bind(('', 12001)) + +def readFile(): + with open('/home/kevin/homeCheck/times.txt', 'r') as content_file: + content = content_file.read() + return content + +while True: + # Save the message and return address to variables. + message, address = serverSocket.recvfrom(1024) + + print(message, address) # Debug print + + # This should prob be cases and not if's, but works to get the right info user requests. + if (message == 'get_times'): + return_message = readFile() + + # Returns message to return address. + serverSocket.sendto(return_message, address) diff --git a/times.txt b/times.txt new file mode 100755 index 0000000..293cfee --- /dev/null +++ b/times.txt @@ -0,0 +1,5 @@ +Elias:1486726563.16 +Kevin:1486726563.16 +Nora:1486712582.96 +Inge:1486726983.5 +Bazzinga:1486726026.07