Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #########################################################################
- ## Update a file with a list of mac adress from (wireless routers) #
- ## #
- ## (working on ubuntu with superuser right) #
- ## #
- ## command: 'sudo python macfisher.py' #
- #########################################################################
- ## set import
- import os,string
- from __future__ import with_statement
- ## set command line and filename output destination
- command="iwlist wlan0 scan" # define command : scann wireless network
- filename = "test" # define output file
- command_line= command + ">" + filename # define command line
- ### open MAC adress archive file
- print '\n'+ "Open old archive file ..."
- archivemacfilename="maclist" # define archive name
- try:
- # with was imported by from __future__ import with_statement
- with open(archivemacfilename,"r") as archivemacfile # open archive file. This syntax open and close file automatically
- stringarchivemac=archivemacfile.read() # to read the content
- except:
- stringarchivemac=""
- ## run command line
- print "Make a scan ..."
- val = os.system(command_line) # run it !
- ## file processing
- with open(filename, 'r') as FILE: # open command output file. This syntax open and close file automatically
- cp_new=0 # define the count for new adress
- for line in FILE: # read the file
- if line.find('Cell')>-1: # if the line contain a MAC adress
- C = line.split()[-1] # split the line
- if stringarchivemac.find(C)==-1: # if the adress is new
- stringarchivemac=stringarchivemac+C+"\n" # add
- cp_new=cp_new+1
- os.remove(filename) # delete file
- ### update du fichier avec les nouvelles
- if cp_new<>0: # if new adress(es) detected
- print "Archive file were updated with " + str(cp_new) + " new address(es)."
- archivemacfilename="maclist" # open archive mac adress file
- with open(archivemacfilename,"a") as archivemacfile: # to write
- archivemacfile.write(stringarchivemac) # the update
- else:
- print "No update for archive file."
- print "\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement