Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
823432c
Test to see if a directory exists, if not create it
geekcomputers Nov 30, 2011
eecf6ef
A simple script to read a list of machine and carry out an nslookup o…
geekcomputers Jan 7, 2012
89f394e
A simple python script that will ping a range of a subnet when you su…
geekcomputers Jan 17, 2012
f1b3aa4
Script to check users home directory, if the directory does not exist…
geekcomputers Jan 17, 2012
c575cfb
Very simple way to gather some OS information
geekcomputers Jan 17, 2012
5d973b8
This is a simple script that will print out x number of lines of text…
geekcomputers Jan 17, 2012
cd3692d
This will move all files in one directory that are over x days old to…
geekcomputers Jan 17, 2012
910dbcd
This display information about the file you give it
geekcomputers Jan 17, 2012
7753eb4
This script wil go through a directory (hard coded) and using the pro…
geekcomputers Jan 17, 2012
c385d1a
README File
geekcomputers Jan 17, 2012
ef91181
This will move all files in one directory that are over x days to ano…
geekcomputers Feb 17, 2012
c24ef9d
Zip up all the logs in the given directory
geekcomputers Feb 29, 2012
5c19614
This simple script loads everything I need to carry out the daily che…
geekcomputers Feb 29, 2012
59a9088
This will list all the files in the given directory, it will also go …
geekcomputers Feb 29, 2012
7937257
Checks to see if a directory exists in the users home directory, if n…
geekcomputers Jun 12, 2012
a5a27e9
Tests to see if the directory testdir exists, if not it will create t…
geekcomputers Jun 12, 2012
8120631
Show file information for a given file
geekcomputers Jun 12, 2012
439bc59
This script will search for all *.log files in the given directory, z…
geekcomputers Jun 12, 2012
3cea6b6
This will move all the files from the src directory that are over 240…
geekcomputers Jun 12, 2012
7fee5ea
This very simple script opens the file server_list.txt and the does a…
geekcomputers Jun 12, 2012
1436ab9
Displays some information about the OS you are running this script on
geekcomputers Jun 13, 2012
8d46c87
This script will check to see if all of the environment variables I r…
geekcomputers Jun 13, 2012
02d85f2
This script will, depending on the arguments supplied will ping the s…
geekcomputers Jun 13, 2012
1445ef1
After supplying the first 3 octets it will scan the final range for a…
geekcomputers Jun 13, 2012
5ac130d
This very simple script open a file and prints out 100 lines of whate…
geekcomputers Jun 13, 2012
7fe5b04
This goes through the server list and pings the machine, if it is up …
geekcomputers Jun 13, 2012
6dad681
Zip up all the logs in the given directory
geekcomputers Jun 13, 2012
4f71048
This scans my scripts directory and gives a count of the different ty…
geekcomputers Jun 14, 2012
d1c3890
This will list all the files in the given directory, it will also go …
geekcomputers Jun 14, 2012
5c9d65f
This will scan the current directory and all subdirectories and displ…
geekcomputers Jul 21, 2012
a8fd034
This scans my scripts directory and gives a count of the different ty…
geekcomputers Jul 21, 2012
168b5a4
README File, information on all the scripts
geekcomputers Jul 21, 2012
b3d5db6
This will batch rename a group of files in a given directory, once yo…
geekcomputers Aug 14, 2012
f375142
README File, information on all the scripts
geekcomputers Aug 14, 2012
855560c
Script to check a file
geekcomputers May 30, 2013
45f9027
Old school password cracker
geekcomputers May 30, 2013
e056760
Portscanner, host and list of ports
geekcomputers May 30, 2013
7bd4be8
Checks version of SQLITE Database and shows tables in the database
geekcomputers Jun 11, 2013
81df6c2
Check directory or existence of SQLITE files
geekcomputers Jun 11, 2013
f03667e
This checks my database to check my master tables are there
geekcomputers Jun 11, 2013
e7488fb
Carry out a nmap scan in python
geekcomputers Jun 14, 2013
95b056d
Like ps on Unix/Linux
geekcomputers Jun 14, 2013
86f99db
Rename a bunch of files to a new extension
geekcomputers Jun 15, 2013
1a0cf45
I use this to backup my automator services
geekcomputers Jun 15, 2013
4903991
Depending on the paramters I pass this will create a script empty scr…
geekcomputers Jun 15, 2013
7513130
My daily checks script
geekcomputers Jun 15, 2013
ea5a38e
Use this to connect to work pc
geekcomputers Jun 15, 2013
858a666
Changed to functions, and check os before running the program
geekcomputers Jun 17, 2013
4ac2222
Displays files in the recyclebin
geekcomputers Jun 28, 2013
673a4e1
Pulss servers from a SQLITE database and them pings them in turn
geekcomputers Jun 28, 2013
c7a0844
Update testlines.py
bevennyamande Mar 26, 2015
2af042e
Update osinfo.py with better interface
y12uc231 Apr 5, 2015
2c432c0
added text-to-speech feature using pyttsx3
YT116 Apr 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
Project Hub 🚀
A collection of various Python projects, including applications developed during my internship and personal learning journey.

Expand Down Expand Up @@ -30,3 +31,42 @@ A collection of various Python projects, including applications developed during
- 🐍 **Snake Game** – A classic Snake game made with Tkinter.
- ❌⭕ **Tic Tac Toe** – A two-player Tic Tac Toe game with an AI opponent.
- 📂 **Other Files** – Additional scripts and utilities for various tasks.
=======
Here is some more detailed information about the scripts I have written. I do not consider myself a programmer, I create these little programs as experiments to have a play with the language, or to solve a problem for myself. I would gladly accept pointers from others to improve the code and make it more efficient, or simplify the code. If you would like to make any comments then please feel free to email me at craig@geekcomputers.co.uk.

In the scripts the comments etc are lined up correctly when they are viewed in Notepad++. This is what I use to code Python scripts.

batch_file_rename.py - This will batch rename a group of files in a given directory, once you pass the current and new extensions

create_dir_if_not_there.py - Checks to see if a directory exists in the users home directory, if not then create it

dir_test.py - Tests to see if the directory testdir exists, if not it will create the directory for you

env_check.py - This script will check to see if all of the environment variables I require are set

fileinfo.py - Show file information for a given file

folder_size.py - This will scan the current directory and all subdirectories and display the size.

logs.py - This script will search for all *.log files in the given directory, zip them using the program you specify and then date stamp them

move_files_over_x_days.py - This will move all the files from the src directory that are over 240 days old to the destination directory.

nslookup_check.py - This very simple script opens the file server_list.txt and the does an nslookup for each one to check the DNS entry

osinfo.py - Displays some information about the OS you are running this script on

ping_servers.py - This script will, depending on the arguments supplied will ping the servers associated with that application group.

ping_subnet.py - After supplying the first 3 octets it will scan the final range for available addresses

powerdown_startup.py - This goes through the server list and pings the machine, if it's up it will load the putty session, if its not it will notify you.

puttylogs.py - Zip up all the logs in the given directory

script_count.py - This scans my scripts directory and gives a count of the different types of scripts

script_listing.py - This will list all the files in the given directory, it will also go through all the subdirectories as well

testlines.py - This very simple script open a file and prints out 100 lines of whatever is set for the line variable
>>>>>>> 1c54298 (Rename README to README.md)
314 changes: 314 additions & 0 deletions ation

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions backup_automater_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Script Name : backup_automater_services.py
# Author : Craig Richards
# Created : 24th October 2012
# Last Modified :
# Version : 1.0

# Modifications :

# Description : This will go through and backup all my automator services workflows

import shutil # Load the library module
import datetime # Load the library module
import os # Load the library module

today=datetime.date.today() # Get Today's date
todaystr=today.isoformat() # Format it so we can use the format to create the directory

confdir=os.getenv("my_config") # Set the variable by getting the value from the OS setting
dropbox=os.getenv("dropbox") # Set the variable by getting the value from the OS setting
conffile = ('services.conf') # Set the variable as the name of the configuration file
conffilename=os.path.join(confdir, conffile) # Set the variable by combining the path and the file name
sourcedir=os.path.expanduser('~/Library/Services/') # Source directory of where the scripts are located
destdir=os.path.join(dropbox, "My_backups"+"/"+"Automater_services"+todaystr+"/") # Combine several settings to create the destination backup directory

for file_name in open(conffilename): # Walk through the configuration file
fname = file_name.strip() # Strip out the blank lines from the configuration file
if fname: # For the lines that are not blank
sourcefile=os.path.join(sourcedir, file_name.strip()) # Get the name of the source files to backup
destfile=os.path.join(destdir, file_name.strip()) # Get the name of the destination file names
shutil.copytree(sourcefile, destfile) # Copy the directories
25 changes: 25 additions & 0 deletions batch_file_rename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Script Name : batch_file_rename.py
# Author : Craig Richards
# Created : 6th August 2012
# Last Modified :
# Version : 1.0

# Modifications :

# Description : This will batch rename a group of files in a given directory, once you pass the current and new extensions

import os # Load the library module
import sys # Load the library module

work_dir=sys.argv[1] # Set the variable work_dir with the first argument passed
old_ext=sys.argv[2] # Set the variable work_dir with the first argument passed
new_ext=sys.argv[3] # Set the variable work_dir with the first argument passed

files = os.listdir(work_dir) # Set the variable files, by listing everything in the directory
for filename in files: # Loop through the files
file_ext = os.path.splitext(filename)[1] # Get the file extension
if old_ext == file_ext: # Start of the logic to check the file extensions, if old_ext = file_ext
newfile = filename.replace(old_ext, new_ext) # Set newfile to be the filename, replaced with the new extension
os.rename( # Write the files
os.path.join(work_dir, filename),
os.path.join(work_dir, newfile))
37 changes: 37 additions & 0 deletions check_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Script Name : check_file.py
# Author : Craig Richards
# Created : 20 May 2013
# Last Modified :
# Version : 1.0

# Modifications :

# Description : Check a file exists and that we can read the file

import sys # Import the Modules
import os # Import the Modules

# Readfile Functions which open the file that is passed to the script

def readfile(filename):
f = open(filename, 'r')
line = f.read()
print line

def main():
if len(sys.argv) == 2: # Check the arguments passed to the script
filename = sys.argv[1] # The filename is the first argument
if not os.path.isfile(filename): # Check the File exists
print '[-] ' + filename + ' does not exist.'
exit(0)
if not os.access(filename, os.R_OK): # Check you can read the file
print '[-] ' + filename + ' access denied'
exit(0)
else:
print '[-] Usage: ' + str(sys.argv[0]) + ' <filename>' # Print usage if not all parameters passed/Checked
exit(0)
print '[+] Reading from : ' + filename # Display Message and read the file contents
readfile(filename)

if __name__ == '__main__':
main()
39 changes: 39 additions & 0 deletions check_for_sqlite_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Script Name : check_for_sqlite_files.py
# Author : Craig Richards
# Created : 07 June 2013
# Last Modified :
# Version : 1.0

# Modifications :

# Description : Scans directories to check if there are any sqlite files in there

import os

def isSQLite3(filename):
from os.path import isfile, getsize

if not isfile(filename):
return False
if getsize(filename) < 100: # SQLite database file header is 100 bytes
return False
else:
fd = open(filename, 'rb')
Header = fd.read(100)
fd.close()

if Header[0:16] == 'SQLite format 3\000':
return True
else:
return False

log=open('sqlite_audit.txt','w')
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')
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')
14 changes: 14 additions & 0 deletions create_dir_if_not_there.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Script Name : create_dir_if_not_there.py
# Author : Craig Richards
# Created : 09th January 2012
# Last Modified :
# Version : 1.0
# Modifications :

# Description : Checks to see if a directory exists in the users home directory, if not then create it

import os # Import the OS module
home=os.path.expanduser("~") # Set the variable home by expanding the users set home directory
print home # Print the location
if not os.path.exists(home+'/testdir'): # Check to see if the directory exists
os.makedirs(home+'/testdir') # If not create the directory, inside their home directory
58 changes: 58 additions & 0 deletions daily_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Script Name : daily_checks.py
# Author : Craig Richards
# Created : 07th December 2011
# Last Modified : 01st May 2013
# Version : 1.4

# Modifications : 1.1 Removed the static lines for the putty sessions, it now reads a file, loops through and makes the connections.
# : 1.2 Added a variable filename=sys.argv[0] , as when you use __file__ it errors when creating an exe with py2exe.
# : 1.3 Changed the server_list.txt file name and moved the file to the config directory.
# : 1.4 Changed some settings due to getting a new pc

# Description : This simple script loads everything I need to carry out the daily checks for our systems.

import platform # Load the Library Module
import os # Load the Library Module
import subprocess # Load the Library Module
import sys # Load the Library Module

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

def print_docs(): # Function to print the daily checks automatically
print "Printing Daily Check Sheets:"
# The command below passes the command line string to open word, open the document, print it then close word down
subprocess.Popen(["C:\\Program Files (x86)\Microsoft Office\Office14\winword.exe", "P:\\\\Documentation\\Daily Docs\\Back office Daily Checks.doc", "/mFilePrintDefault", "/mFileExit"]).communicate()

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

def euroclear_docs():
# The command below opens IE and loads the Euroclear password document
subprocess.Popen('"C:\\Program Files\\Internet Explorer\\iexplore.exe"' '"file://fs1\pub_b\Pub_Admin\Documentation\Settlements_Files\PWD\Eclr.doc"')

# End of the functions

# Start of the Main Program

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()
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
12 changes: 12 additions & 0 deletions dir_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Script Name : dir_test.py
# Author : Craig Richards
# Created : 29th November 2011
# Last Modified :
# Version : 1.0
# Modifications :

# 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
24 changes: 24 additions & 0 deletions env_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Script Name : env_check.py
# Author : Craig Richards
# Created : 14th May 2012
# Last Modified :
# Version : 1.0

# Modifications :

# Description : This script will check to see if all of the environment variables I require are set

import os

confdir = os.getenv("my_config") # Set the variable confdir from the OS environment variable
conffile = 'env_check.conf' # Set the variable conffile
conffilename=os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together

for env_check in open(conffilename): # Open the config file and read all the settings
env_check = env_check.strip() # Set the variable as itsself, but strip the extra text out
print '[{}]'.format(env_check) # Format the Output to be in Square Brackets
newenv = os.getenv(env_check) # Set the variable newenv to get the settings from the OS what is currently set for the settings out the configfile
if newenv is None: # If it doesn't exist
print env_check, 'is not set' # Print it is not set
else: # Else if it does exist
print 'Current Setting for {}={}\n'.format(env_check, newenv) # Print out the details
47 changes: 47 additions & 0 deletions fileinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Script Name : fileinfo.py
# Author : Not sure where I got this from
# Created : 28th November 2011
# Last Modified :
# Version : 1.0
# Modifications :

# Description : Show file information for a given file


# get file information using os.stat()
# tested with Python24 vegsaeat 25sep2006
import os
import stat # index constants for os.stat()
import time
# pick a file you have ...
file_name = raw_input("Enter a file name: ")
file_stats = os.stat(file_name)
# create a dictionary to hold file info
file_info = {
'fname': file_name,
'fsize': file_stats [stat.ST_SIZE],
'f_lm': time.strftime("%d/%m/%Y %I:%M:%S %p",time.localtime(file_stats[stat.ST_MTIME])),
'f_la': time.strftime("%d/%m/%Y %I:%M:%S %p",time.localtime(file_stats[stat.ST_ATIME])),
'f_ct': time.strftime("%d/%m/%Y %I:%M:%S %p",time.localtime(file_stats[stat.ST_CTIME]))
}
print
print "file name = %(fname)s" % file_info
print "file size = %(fsize)s bytes" % file_info
print "last modified = %(f_lm)s" % file_info
print "last accessed = %(f_la)s" % file_info
print "creation time = %(f_ct)s" % file_info
print
if stat.S_ISDIR(file_stats[stat.ST_MODE]):
print "This a directory"
else:
print "This is not a directory"
print
print "A closer look at the os.stat(%s) tuple:" % file_name
print file_stats
print
print "The above tuple has the following sequence:"
print """st_mode (protection bits), st_ino (inode number),
st_dev (device), st_nlink (number of hard links),
st_uid (user ID of owner), st_gid (group ID of owner),
st_size (file size, bytes), st_atime (last access time, seconds since epoch),
st_mtime (last modification time), st_ctime (time of creation, Windows)"""
22 changes: 22 additions & 0 deletions folder_size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Script Name : folder_size.py
# Author : Craig Richards
# Created : 19th July 2012
# Last Modified :
# Version : 1.0

# Modifications :

# Description : This will scan the current directory and all subdirectories and display the size.

import os # Load the library module

directory = '.' # Set the variable directory to be the current directory
dir_size = 0 # Set the size to 0
for (path, dirs, files) in os.walk(directory): # Walk through all the directories
for file in files: # Get all the files
filename = os.path.join(path, file)
dir_size += os.path.getsize(filename) # Get the sizes, the following lines print the sizes in bytes, Kb, Mb and Gb
print "Folder Size in Bytes = %0.2f Bytes" % (dir_size)
print "Folder Size in Kilobytes = %0.2f KB" % (dir_size/1024.0)
print "Folder Size in Megabytes = %0.2f MB" % (dir_size/1024/1024.0)
print "Folder Size in Gigabytes = %0.2f GB" % (dir_size/1024/1024/1024.0)
21 changes: 21 additions & 0 deletions logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Script Name : logs.py
# Author : Craig Richards
# Created : 13th October 2011
# Last Modified :
# Version : 1.1
# Modifications : 1.1 - Added the variable zip_program so you can set it for the zip program on whichever OS, so to run on a different OS just change the locations of these two variables.

# Description : This script will search for all *.log files in the given directory, zip them using the program you specify and then date stamp them

import os # Load the Library Module
from time import strftime # Load just the strftime Module from Time

logsdir="c:\puttylogs" # Set the Variable logsdir
zip_program="zip.exe" # Set the Variable zip_program - 1.1

for files in os.listdir(logsdir): # Find all the files in the directory
if files.endswith(".log"): # Check to ensure the files in the directory end in .log
files1=files+"."+strftime("%Y-%m-%d")+".zip" # Create the Variable files1, this is the files in the directory, then we add a suffix with the date and the zip extension
os.chdir(logsdir) # Change directory to the logsdir
os.system(zip_program + " " + files1 +" "+ files) # Zip the logs into dated zip files for each server. - 1.1
os.remove(files) # Remove the original log files
1 change: 1 addition & 0 deletions move_files_over_x_days.py
Original file line number Diff line number Diff line change
@@ -0,0 +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 filessrc = 'u:\\test' # Set the source directorydst = 'c:\\test' # Set the destination directorynow = time.time() # Get the current timefor 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
Expand Down
Loading