1

By using some Python codes in Ubunto terminal with nmap or arp-scan I got result of all devices mac addresses which are connected with my router .. and i store that results in one text file1 which contain only mac address like that :

C4:E9:A4:30:98:22
5C:8A:F2:9B:0C:CD
E8:A9:60:4C:56:D1
C8:0A:3F:85:MD:D6

I have also already another text file2 which contain all mac addresses in the building.

i need help in script that i can compare between file1 and file2 then record which mac address in file1 and its from list in file2 are connected with my router - then save it in third file3 .

may this will not be clear for some people .so. i work with system that will take attendance in company by using phone mac address for employees .. hope this will help to understand my point .. and please help i am beginner :) thank you

EDIT

I already did this:

for i in range(2): 
    os.system("ping -c5 -b 192.168.0.255") os.system("nmap -sP 192.168.0.1/24 >rec.txt") 
    os.system("grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' rec.txt >mac.txt")
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
coder2017
  • 11
  • 3
  • Show us what you've done so far. Stackoverflow is not a do-it-for-me site. – TkTech Feb 01 '17 at 17:42
  • yes bro sorry i did this : for i in range(2): os.system("ping -c5 -b 192.168.0.255") os.system("nmap -sP 192.168.0.1/24 >rec.txt") os.system("grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' rec.txt >mac.txt") – coder2017 Feb 01 '17 at 17:44
  • Next time please just edit your question. Thank you. – kiecodes Feb 01 '17 at 17:47
  • To extract all addresses from file1 that are in file2, you can do this: `grep -Ff file1 file2 > file3` ([see here](http://stackoverflow.com/questions/17863301/how-to-grep-with-a-list-of-words)). – Norman Feb 01 '17 at 19:01
  • thank you so much Norman.. the code was help .. but if i scan my network again it will record again what is now connected .. and past macs will deleted .. is there any way to make record in same file for each scan? – coder2017 Feb 01 '17 at 19:51
  • Use an append pipe `>>` instead of overwriting the file as is. – silentsod Feb 01 '17 at 21:07
  • thank you i got it.. but i have small poblem than i have 3 phones to check every time .. but when the screen of phone is on then the mac address shown in the file .. when the screen is off then that phone will not shown in the scan and file : i used : nmap commands and also arp-scan commands its same things .. any suggestions please ? – coder2017 Feb 01 '17 at 21:36

0 Answers0