diff --git a/check_for_sqlite_files.py b/check_for_sqlite_files.py index c5f9a865890..3f65fbc8011 100644 --- a/check_for_sqlite_files.py +++ b/check_for_sqlite_files.py @@ -30,9 +30,9 @@ def isSQLite3(filename): for r,d,f in os.walk(r'.'): for files in f: if isSQLite3(files): - print files - print "[+] '%s' **** is a SQLITE database file **** " % os.path.join(r,files) - log.write("[+] '%s' **** is a SQLITE database file **** " % files+'\n') + print files + print "[+] '%s' **** is a SQLITE database file **** " % os.path.join(r,files) + log.write("[+] '%s' **** is a SQLITE database file **** " % files+'\n') else: - log.write("[-] '%s' is NOT a sqlite database file" % os.path.join(r,files)+'\n') - log.write("[-] '%s' is NOT a sqlite database file" % files+'\n') + log.write("[-] '%s' is NOT a sqlite database file" % os.path.join(r,files)+'\n') + log.write("[-] '%s' is NOT a sqlite database file" % files+'\n') diff --git a/daily_checks.py b/daily_checks.py index 275d152cc32..1730154bacd 100644 --- a/daily_checks.py +++ b/daily_checks.py @@ -20,10 +20,10 @@ from time import strftime # Load just the strftime Module from Time def clear_screen(): # Function to clear the screen - if os.name == "posix": # Unix/Linux/MacOS/BSD/etc - os.system('clear') # Clear the Screen - elif os.name in ("nt", "dos", "ce"): # DOS/Windows - os.system('CLS') # Clear the Screen + if os.name == "posix": # Unix/Linux/MacOS/BSD/etc + os.system('clear') # Clear the Screen + elif os.name in ("nt", "dos", "ce"): # DOS/Windows + os.system('CLS') # Clear the Screen def print_docs(): # Function to print the daily checks automatically print "Printing Daily Check Sheets:" @@ -33,7 +33,7 @@ def print_docs(): # Function to print the daily checks automatically def putty_sessions(): # Function to load the putty sessions I need for server in open(conffilename): # Open the file server_list.txt, loop through reading each line - 1.1 -Changed - 1.3 Changed name to use variable conffilename subprocess.Popen(('putty -load '+server)) # Open the PuTTY sessions - 1.1 - + def rdp_sessions(): print "Loading RDP Sessions:" subprocess.Popen("mstsc eclr.rdp") # Open up a terminal session connection and load the euroclear session @@ -46,19 +46,19 @@ def euroclear_docs(): # Start of the Main Program def main(): - filename = sys.argv[0] # Create the variable filename - confdir = os.getenv("my_config") # Set the variable confdir from the OS environment variable - 1.3 - conffile = ('daily_checks_servers.conf') # Set the variable conffile - 1.3 - conffilename = os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together - 1.3 - clear_screen() # Call the clear screen function + filename = sys.argv[0] # Create the variable filename + confdir = os.getenv("my_config") # Set the variable confdir from the OS environment variable - 1.3 + conffile = ('daily_checks_servers.conf') # Set the variable conffile - 1.3 + conffilename = os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together - 1.3 + clear_screen() # Call the clear screen function - # The command below prints a little welcome message, as well as the script name, the date and time and where it was run from. - print "Good Morning " + os.getenv('USERNAME') + ", " + filename, "ran at", strftime("%Y-%m-%d %H:%M:%S"), "on",platform.node(), "run from",os.getcwd() + # The command below prints a little welcome message, as well as the script name, the date and time and where it was run from. + print "Good Morning " + os.getenv('USERNAME') + ", " + filename, "ran at", strftime("%Y-%m-%d %H:%M:%S"), "on",platform.node(), "run from",os.getcwd() - print_docs() # Call the print_docs function - putty_sessions() # Call the putty_session function - rdp_sessions() # Call the rdp_sessions function - euroclear_docs() # Call the euroclear_docs function + print_docs() # Call the print_docs function + putty_sessions() # Call the putty_session function + rdp_sessions() # Call the rdp_sessions function + euroclear_docs() # Call the euroclear_docs function if __name__ == '__main__': - main() + main() diff --git a/dir_test.py b/dir_test.py index 0cf9d5aa6b2..8d701055c0c 100644 --- a/dir_test.py +++ b/dir_test.py @@ -7,6 +7,7 @@ # Description : Tests to see if the directory testdir exists, if not it will create the directory for you -import os # Import the OS module -if not os.path.exists('testdir'): # Check to see if it exists - os.makedirs('testdir') # Create the directory +import os # Import the OS module + +if not os.path.exists('testdir'): # Check to see if it exists + os.makedirs('testdir') # Create the directory diff --git a/move_files_over_x_days.py b/move_files_over_x_days.py index e10c933fa4e..8f2628e435e 100644 --- a/move_files_over_x_days.py +++ b/move_files_over_x_days.py @@ -1 +1 @@ -# Script Name : move_files_over_x_days.py # Author : Craig Richards # Created : 8th December 2011 # Last Modified : # Version : 1.0 # Modifications : # Description : This will move all the files from the src directory that are over 240 days old to the destination directory. import shutil, sys, time, os # Import the header files src = 'u:\\test' # Set the source directory dst = 'c:\\test' # Set the destination directory now = time.time() # Get the current time for f in os.listdir(src): # Loop through all the files in the source directory if os.stat(f).st_mtime < now - 240 * 86400: # Work out how old they are, if they are older than 240 days old if os.path.isfile(f): # Check it's a file shutil.move(f, dst) # Move the files \ No newline at end of file +# Script Name : move_files_over_x_days.py # Author : Craig Richards # Created : 8th December 2011 # Last Modified : # Version : 1.0 # Modifications : # Description : This will move all the files from the src directory that are over 240 days old to the destination directory. import shutil, sys, time, os # Import the header files src = 'u:\\test' # Set the source directory dst = 'c:\\test' # Set the destination directory now = time.time() # Get the current time for f in os.listdir(src): # Loop through all the files in the source directory if os.stat(f).st_mtime < now - 240 * 86400: # Work out how old they are, if they are older than 240 days old if os.path.isfile(f): # Check it's a file shutil.move(f, dst) # Move the files \ No newline at end of file diff --git a/ping_servers.py b/ping_servers.py index 13fca799899..c386b0d8cd4 100644 --- a/ping_servers.py +++ b/ping_servers.py @@ -15,35 +15,35 @@ if '-h' in sys.argv or '--h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv: # Help Menu if called print ''' You need to supply the application group for the servers you want to ping, i.e. - dms - swaps - + dms + swaps + Followed by the site i.e. - 155 - bromley''' + 155 + bromley''' sys.exit(0) else: - if (len(sys.argv) < 3): # If no arguments are passed,display the help/instructions on how to run the script - sys.exit ('\nYou need to supply the app group. Usage : ' + filename + ' followed by the application group i.e. \n \t dms or \n \t swaps \n then the site i.e. \n \t 155 or \n \t bromley') + if (len(sys.argv) < 3): # If no arguments are passed,display the help/instructions on how to run the script + sys.exit ('\nYou need to supply the app group. Usage : ' + filename + ' followed by the application group i.e. \n \t dms or \n \t swaps \n then the site i.e. \n \t 155 or \n \t bromley') + + appgroup = sys.argv[1] # Set the variable appgroup as the first argument you supply + site = sys.argv[2] # Set the variable site as the second argument you supply + + if os.name == "posix": # Check the os, if it's linux then + myping = "ping -c 2 " # This is the ping command + elif os.name in ("nt", "dos", "ce"): # Check the os, if it's windows then + myping = "ping -n 2 " # This is the ping command - appgroup = sys.argv[1] # Set the variable appgroup as the first argument you supply - site = sys.argv[2] # Set the variable site as the second argument you supply - - if os.name == "posix": # Check the os, if it's linux then - myping = "ping -c 2 " # This is the ping command - elif os.name in ("nt", "dos", "ce"): # Check the os, if it's windows then - myping = "ping -n 2 " # This is the ping command - - if 'dms' in sys.argv: # If the argument passed is dms then - appgroup = 'dms' # Set the variable appgroup to dms - elif 'swaps' in sys.argv: # Else if the argment passed is swaps then - appgroup = 'swaps' # Set the variable appgroup to swaps - - if '155' in sys.argv: # If the argument passed is 155 then - site = '155' # Set the variable site to 155 - elif 'bromley' in sys.argv: # Else if the argument passed is bromley - site = 'bromley' # Set the variable site to bromley + if 'dms' in sys.argv: # If the argument passed is dms then + appgroup = 'dms' # Set the variable appgroup to dms + elif 'swaps' in sys.argv: # Else if the argment passed is swaps then + appgroup = 'swaps' # Set the variable appgroup to swaps + + if '155' in sys.argv: # If the argument passed is 155 then + site = '155' # Set the variable site to 155 + elif 'bromley' in sys.argv: # Else if the argument passed is bromley + site = 'bromley' # Set the variable site to bromley filename = sys.argv[0] # Sets a variable for the script name logdir = os.getenv("logs") # Set the variable logdir by getting the OS environment logs @@ -55,10 +55,10 @@ f = open(logfilename, "w") # Open a logfile to write out the output for server in open(conffilename): # Open the config file and read each line - 1.2 - ret = subprocess.call(myping + server, shell=True,stdout=f,stderr=subprocess.STDOUT) # Run the ping command for each server in the list. - if ret == 0: # Depending on the response - f.write (server.strip() + " is alive" + "\n") # Write out that you can receive a reponse - else: - f.write (server.strip() + " did not respond" + "\n") # Write out you can't reach the box - + ret = subprocess.call(myping + server, shell=True,stdout=f,stderr=subprocess.STDOUT) # Run the ping command for each server in the list. + if ret == 0: # Depending on the response + f.write (server.strip() + " is alive" + "\n") # Write out that you can receive a reponse + else: + f.write (server.strip() + " did not respond" + "\n") # Write out you can't reach the box + print ("\n\tYou can see the results in the logfile : "+ logfilename); # Show the location of the logfile \ No newline at end of file diff --git a/ping_subnet.py b/ping_subnet.py index 657095af663..4ad1fcc1f1f 100644 --- a/ping_subnet.py +++ b/ping_subnet.py @@ -20,20 +20,20 @@ sys.exit(0) else: - if (len(sys.argv) < 2): # If no arguments are passed then display the help and instructions on how to run the script - sys.exit (' You need to supply the first octets of the address Usage : ' + filename + ' 111.111.111') - - subnet = sys.argv[1] # Set the variable subnet as the three octets you pass it - - if os.name == "posix": # Check the os, if it's linux then - myping = "ping -c 2 " # This is the ping command - elif os.name in ("nt", "dos", "ce"): # Check the os, if it's windows then - myping = "ping -n 2 " # This is the ping command - - f = open('ping_'+subnet+'.log', 'w') # Open a logfile - for ip in range(2,255): # Set the ip variable for the range of numbers - ret = subprocess.call(myping + str(subnet)+"."+str(ip) , shell=True,stdout=f,stderr=subprocess.STDOUT) # Run the command pinging the servers - if ret == 0: # Depending on the response - f.write (subnet+"."+str(ip) + " is alive" + "\n") # Write out that you can receive a reponse - else: - f.write (subnet+"."+str(ip) + " did not respond" + "\n") # Write out you can't reach the box \ No newline at end of file + if (len(sys.argv) < 2): # If no arguments are passed then display the help and instructions on how to run the script + sys.exit (' You need to supply the first octets of the address Usage : ' + filename + ' 111.111.111') + + subnet = sys.argv[1] # Set the variable subnet as the three octets you pass it + + if os.name == "posix": # Check the os, if it's linux then + myping = "ping -c 2 " # This is the ping command + elif os.name in ("nt", "dos", "ce"): # Check the os, if it's windows then + myping = "ping -n 2 " # This is the ping command + + f = open('ping_'+subnet+'.log', 'w') # Open a logfile + for ip in range(2,255): # Set the ip variable for the range of numbers + ret = subprocess.call(myping + str(subnet)+"."+str(ip) , shell=True,stdout=f,stderr=subprocess.STDOUT) # Run the command pinging the servers + if ret == 0: # Depending on the response + f.write (subnet+"."+str(ip) + " is alive" + "\n") # Write out that you can receive a reponse + else: + f.write (subnet+"."+str(ip) + " did not respond" + "\n") # Write out you can't reach the box \ No newline at end of file diff --git a/powerup_checks.py b/powerup_checks.py index 90b6babf571..477f72ca4ee 100644 --- a/powerup_checks.py +++ b/powerup_checks.py @@ -29,28 +29,28 @@ You need to pass an argument, the options the script expects is - -site1 For the Servers relating to site1 - -site2 For the Servers located in site2''' - + -site1 For the Servers relating to site1 + -site2 For the Servers located in site2''' + def windows(): # This is the function to run if it detects the OS is windows. - f = open(outputfile, 'a') # Open the logfile - for server in open(serverfile,'r'): # Read the list of servers from the list - #ret = subprocess.call("ping -n 3 %s" % server.strip(), shell=True,stdout=open('NUL', 'w'),stderr=subprocess.STDOUT) # Ping the servers in turn - ret = subprocess.call("ping -n 3 %s" % server.strip(),stdout=open('NUL', 'w'),stderr=subprocess.STDOUT) # Ping the servers in turn - if ret == 0: # Depending on the response - f.write ("%s: is alive" % server.strip().ljust(15) + "\n") # Write out to the logfile is the server is up - else: - f.write ("%s: did not respond" % server.strip().ljust(15) + "\n") # Write to the logfile if the server is down - - + f = open(outputfile, 'a') # Open the logfile + for server in open(serverfile,'r'): # Read the list of servers from the list + #ret = subprocess.call("ping -n 3 %s" % server.strip(), shell=True,stdout=open('NUL', 'w'),stderr=subprocess.STDOUT) # Ping the servers in turn + ret = subprocess.call("ping -n 3 %s" % server.strip(),stdout=open('NUL', 'w'),stderr=subprocess.STDOUT) # Ping the servers in turn + if ret == 0: # Depending on the response + f.write ("%s: is alive" % server.strip().ljust(15) + "\n") # Write out to the logfile is the server is up + else: + f.write ("%s: did not respond" % server.strip().ljust(15) + "\n") # Write to the logfile if the server is down + + def linux(): # This is the function to run if it detects the OS is nix. - f = open('server_startup_'+strftime("%Y-%m-%d")+'.log', 'a') # Open the logfile - for server in open(serverfile,'r'): # Read the list of servers from the list - ret = subprocess.call("ping -c 3 %s" % server, shell=True,stdout=open('/dev/null', 'w'),stderr=subprocess.STDOUT) # Ping the servers in turn - if ret == 0: # Depending on the response - f.write ("%s: is alive" % server.strip().ljust(15) + "\n") # Write out to the logfile is the server is up - else: - f.write ("%s: did not respond" % server.strip().ljust(15) + "\n") # Write to the logfile if the server is down + f = open('server_startup_'+strftime("%Y-%m-%d")+'.log', 'a') # Open the logfile + for server in open(serverfile,'r'): # Read the list of servers from the list + ret = subprocess.call("ping -c 3 %s" % server, shell=True,stdout=open('/dev/null', 'w'),stderr=subprocess.STDOUT) # Ping the servers in turn + if ret == 0: # Depending on the response + f.write ("%s: is alive" % server.strip().ljust(15) + "\n") # Write out to the logfile is the server is up + else: + f.write ("%s: did not respond" % server.strip().ljust(15) + "\n") # Write to the logfile if the server is down def get_servers(query): # Function to get the servers from the database conn = sqlite3.connect(master_db) # Connect to the database @@ -69,7 +69,7 @@ def get_servers(query): # Function to get the ser def main(): # Main Function if os.path.exists(serverfile): # Checks to see if there is an existing server file os.remove(serverfile) # If so remove it - + if len(sys.argv) < 2: # Check there is an argument being passed print text # Display the help text if there isn't one passed sys.exit() # Exit the script @@ -81,16 +81,16 @@ def main(): # Main Function if sys.argv[1].lower().startswith('-site1'): # If the argument is site1 query = 'site1' # Set the variable to have the value site elif sys.argv[1].lower().startswith('-site2'): # Else if the variable is bromley - query = 'site2' # Set the variable to have the value bromley + query = 'site2' # Set the variable to have the value bromley else: print '\n[-] Unknown option [-] ' + text # If an unknown option is passed, let the user know sys.exit(0) get_servers(query) # Call the get servers funtion, with the value from the argument if os.name == "posix": # If the OS is linux. - linux() # Call the linux function + linux() # Call the linux function elif os.name in ("nt", "dos", "ce"): # If the OS is Windows... - windows() # Call the windows function + windows() # Call the windows function print ('\n[+] Check the log file ' + outputfile + ' [+]\n') # Display the name of the log diff --git a/recyclebin.py b/recyclebin.py index 3c1c74bda8d..435935da551 100644 --- a/recyclebin.py +++ b/recyclebin.py @@ -20,14 +20,14 @@ def sid2user(sid): # Start of the function to gather the user return user except: return sid - + def returnDir(): # Start of the function to search through the recyclebin dirs=['c:\\Recycler\\','C:\\Recycled\\','C:\\$RECYCLE.BIN\\'] #dirs=['c:\\$RECYCLE.BIN\\'] for recycleDir in dirs: if os.path.isdir(recycleDir): - return recycleDir + return recycleDir return None def findRecycled(recycleDir): # Start of the function, list the contents of the recyclebin @@ -37,8 +37,8 @@ def findRecycled(recycleDir): # Start of the function, list the contents of the user = sid2user(sid) print '\n[*] Listing Files for User: ' + str(user) for file in files: - print '[+] Found File: ' + str(file) - + print '[+] Found File: ' + str(file) + def main(): recycleDir = returnDir() findRecycled(recycleDir) diff --git a/script_count.py b/script_count.py index 6e737de7b54..d460b2515a3 100644 --- a/script_count.py +++ b/script_count.py @@ -17,16 +17,16 @@ dropbox = os.getenv("dropbox") # Set the variable dropbox by getting the value from the OS environment variable dropbox def clear_screen(): # Function to clear the screen - if os.name == "posix": # Unix/Linux/MacOS/BSD/etc - os.system('clear') # Clear the Screen - elif os.name in ("nt", "dos", "ce"): # DOS/Windows - os.system('CLS') # Clear the Screen + if os.name == "posix": # Unix/Linux/MacOS/BSD/etc + os.system('clear') # Clear the Screen + elif os.name in ("nt", "dos", "ce"): # DOS/Windows + os.system('CLS') # Clear the Screen def count_files(path, extensions): # Start of the function to count the files in the scripts directory, it counts the extension when passed below counter = 0 # Set the counter to 0 for root, dirs, files in os.walk(path): # Loop through all the directories in the given path for file in files: # For all the files - counter += file.endswith(extensions) # Count the files + counter += file.endswith(extensions) # Count the files return counter # Return the count def github(): # Start of the function just to count the files in the github directory @@ -38,7 +38,7 @@ def github(): # Start of the function just to count the fil elif github_count == 0: # Unless the count is 0, then print the following messages print '\nGithub directory is all Clear' else: # If it is any other number then print the following message, showing the number outstanding. - print '\nYou have: ' + str(github_count) + ' waiting to be uploaded to github!!' + print '\nYou have: ' + str(github_count) + ' waiting to be uploaded to github!!' def development(): # Start of the function just to count the files in the development directory dev_dir = os.path.join(path, 'development') # Joins the paths to get the development directory - 1.1 @@ -49,10 +49,10 @@ def development(): # Start of the function just to count the elif dev_count ==0: # Unless the count is 0, then print the following messages print '\nDevelopment directory is all clear' else: - print '\nYou have: ' + str(dev_count) + ' waiting to be finished!!' # If it is any other number then print the following message, showing the number outstanding. + print '\nYou have: ' + str(dev_count) + ' waiting to be finished!!' # If it is any other number then print the following message, showing the number outstanding. clear_screen() # Call the function to clear the screen - + print '\nYou have the following :\n' print 'AutoIT:\t' + str(count_files(path, '.au3')) # Run the count_files function to count the files with the extension we pass print 'Batch:\t' + str(count_files(path, ('.bat', ',cmd'))) # 1.3 diff --git a/script_listing.py b/script_listing.py index 1eca087d61a..5b5f7780da6 100644 --- a/script_listing.py +++ b/script_listing.py @@ -20,5 +20,5 @@ log = open(logfilename, 'w') # Set the variable log and open the logfile for writing for dirpath, dirname, filenames in os.walk(path): # Go through the directories and the subdirectories for filename in filenames: # Get all the filenames - log.write(os.path.join(dirpath, filename)+'\n') # Write the full path out to the logfile + log.write(os.path.join(dirpath, filename)+'\n') # Write the full path out to the logfile print "\nYour logfile " , logfilename, "has been created" # Small message informing the user the file has been created \ No newline at end of file