Skip to content

Commit 067a5c3

Browse files
Merge pull request geekcomputers#102 from VishvajitP/master
PEP8 changes
2 parents 5cc3a1f + caf273f commit 067a5c3

10 files changed

+114
-108
lines changed

logs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Script Name : logs.py
22
# Author : Craig Richards
33
# Created : 13th October 2011
4-
# Last Modified : 14 February 2016
4+
# Last Modified : 14 February 2016
55
# Version : 1.2
66
#
77
# 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.
@@ -12,8 +12,8 @@
1212
import os # Load the Library Module
1313
from time import strftime # Load just the strftime Module from Time
1414

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

1818
for files in os.listdir(logsdir): # Find all the files in the directory
1919
if files.endswith(".log"): # Check to ensure the files in the directory end in .log

merge.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import glob
21
import csv
3-
import pdb
2+
import glob
43
import os
5-
import pandas as pd
4+
import pdb
5+
import pandas as pd
6+
67

78
def main():
89
directory = []
@@ -15,8 +16,8 @@ def main():
1516
frame = pd.DataFrame()
1617
dfs = []
1718
for files in allFiles:
18-
df = pd.read_csv(files,index_col=None, header=0)
19+
df = pd.read_csv(files, index_col=None, header=0)
1920
dfs.append(df)
2021
frame = pd.concat(dfs)
21-
frame.to_csv(ff+"/results.csv")
22+
frame.to_csv(ff + "/results.csv")
2223
main()

move_files_over_x_days.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +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 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
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 shutilimport sysimport timeimport ossrc = '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

new_script.py

+36-36
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Script Name : new_script.py
22
# Author : Craig Richards
33
# Created : 20th November 2012
4-
# Last Modified :
4+
# Last Modified :
55
# Version : 1.0
66

7-
# Modifications :
7+
# Modifications :
88

99
# Description : This will create a new basic template for a new script
1010

@@ -19,48 +19,48 @@
1919
-sql : SQL Script'''
2020

2121
if len(sys.argv) < 3:
22-
print text
23-
sys.exit()
24-
25-
if '-h' in sys.argv or '--h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv:
26-
print text
27-
sys.exit()
28-
else:
22+
print text
23+
sys.exit()
24+
25+
if '-h' in sys.argv or '--h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv:
26+
print text
27+
sys.exit()
28+
else:
2929
if '-python' in sys.argv[1]:
30-
config_file="python.cfg"
31-
extension=".py"
30+
config_file = "python.cfg"
31+
extension = ".py"
3232
elif '-bash' in sys.argv[1]:
33-
config_file="bash.cfg"
34-
extension=".bash"
33+
config_file = "bash.cfg"
34+
extension = ".bash"
3535
elif '-ksh' in sys.argv[1]:
36-
config_file="ksh.cfg"
37-
extension=".ksh"
36+
config_file = "ksh.cfg"
37+
extension = ".ksh"
3838
elif '-sql' in sys.argv[1]:
39-
config_file="sql.cfg"
40-
extension=".sql"
39+
config_file = "sql.cfg"
40+
extension = ".sql"
4141
else:
42-
print 'Unknown option - ' + text
42+
print 'Unknown option - ' + text
4343
sys.exit()
4444

45-
confdir=os.getenv("my_config")
46-
scripts=os.getenv("scripts")
47-
dev_dir="Development"
48-
newfile=sys.argv[2]
49-
output_file=(newfile+extension)
50-
outputdir=os.path.join(scripts,dev_dir)
51-
script=os.path.join(outputdir, output_file)
52-
input_file=os.path.join(confdir,config_file)
53-
old_text=" Script Name : "
54-
new_text=(" Script Name : "+output_file)
45+
confdir = os.getenv("my_config")
46+
scripts = os.getenv("scripts")
47+
dev_dir = "Development"
48+
newfile = sys.argv[2]
49+
output_file = (newfile + extension)
50+
outputdir = os.path.join(scripts,dev_dir)
51+
script = os.path.join(outputdir, output_file)
52+
input_file = os.path.join(confdir,config_file)
53+
old_text = " Script Name : "
54+
new_text = (" Script Name : " + output_file)
5555
if not(os.path.exists(outputdir)):
5656
os.mkdir(outputdir)
57-
newscript = open(script, 'w')
58-
input=open(input_file,'r')
59-
today=datetime.date.today()
60-
old_date= " Created :"
61-
new_date= (" Created : "+today.strftime("%d %B %Y"))
62-
63-
for line in input:
57+
newscript = open(script, 'w')
58+
input = open(input_file, 'r')
59+
today = datetime.date.today()
60+
old_date = " Created :"
61+
new_date = (" Created : " + today.strftime("%d %B %Y"))
62+
63+
for line in input:
6464
line = line.replace(old_text, new_text)
6565
line = line.replace(old_date, new_date)
66-
newscript.write(line)
66+
newscript.write(line)

nmap_scan.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
11
# Script Name : nmap_scan.py
22
# Author : Craig Richards
33
# Created : 24th May 2013
4-
# Last Modified :
4+
# Last Modified :
55
# Version : 1.0
66

7-
# Modifications :
7+
# Modifications :
88

99
# Description : This scans my scripts directory and gives a count of the different types of scripts, you need nmap installed to run this
1010

1111
import nmap # Import the module
1212
import optparse # Import the module
1313

14-
def nmapScan(tgtHost, tgtPort): # Create the function, this fucntion does the scanning
15-
nmScan = nmap.PortScanner()
16-
nmScan.scan(tgtHost, tgtPort)
17-
state = nmScan[tgtHost]['tcp'][int(tgtPort)]['state']
18-
print "[*] " + tgtHost + " tcp/"+tgtPort +" "+state
19-
14+
15+
def nmapScan(tgtHost, tgtPort): # Create the function, this fucntion does the scanning
16+
nmScan = nmap.PortScanner()
17+
nmScan.scan(tgtHost, tgtPort)
18+
state = nmScan[tgtHost]['tcp'][int(tgtPort)]['state']
19+
print "[*] " + tgtHost + " tcp/" + tgtPort + " " + state
20+
21+
2022
def main(): # Main Program
2123
parser = optparse.OptionParser('usage%prog ' + '-H <host> -p <port>') # Display options/help if required
2224
parser.add_option('-H', dest='tgtHost', type='string', help='specify host')
2325
parser.add_option('-p', dest='tgtPort', type='string', help='port')
2426
(options, args) = parser.parse_args()
2527
tgtHost = options.tgtHost
2628
tgtPorts = str(options.tgtPort).split(',')
27-
28-
if (tgtHost == None) | (tgtPorts[0] == None):
29+
30+
if (tgtHost == None) | (tgtPorts[0] == None):
2931
print parser.usage
30-
exit(0)
31-
32-
for tgtPort in tgtPorts: # Scan the hosts with the ports etc
32+
exit(0)
33+
34+
for tgtPort in tgtPorts: # Scan the hosts with the ports etc
3335
nmapScan(tgtHost, tgtPort)
3436

37+
3538
if __name__ == '__main__':
36-
main()
39+
main()

nslookup_check.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Script Name : nslookup_check.py
22
# Author : Craig Richards
33
# Created : 5th January 2012
4-
# Last Modified :
4+
# Last Modified :
55
# Version : 1.0
66

7-
# Modifications :
7+
# Modifications :
88

99
# Description : This very simple script opens the file server_list.txt and the does an nslookup for each one to check the DNS entry
1010

1111
import subprocess # Import the subprocess module
12+
1213
for server in open('server_list.txt'): # Open the file and read each line
13-
subprocess.Popen(('nslookup '+server)) # Run the nslookup command for each server in the list
14+
subprocess.Popen(('nslookup ' + server)) # Run the nslookup command for each server in the list

osinfo.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,31 @@
55
# Version : 1.0
66

77
# Modification 1 : Changed the profile to list again. Order is important. Everytime we run script we don't want to see different ordering.
8-
# Modification 2 : Fixed the AttributeError checking for all properties. Using hasttr().
9-
# Modification 3 : Removed ': ' from properties inside profile.
8+
# Modification 2 : Fixed the AttributeError checking for all properties. Using hasttr().
9+
# Modification 3 : Removed ': ' from properties inside profile.
1010

1111

1212
# Description : Displays some information about the OS you are running this script on
1313

1414
import platform as pl
1515

1616
profile = [
17-
'architecture',
18-
'linux_distribution',
19-
'mac_ver',
20-
'machine',
21-
'node',
22-
'platform',
23-
'processor',
24-
'python_build',
25-
'python_compiler',
26-
'python_version',
27-
'release',
28-
'system',
29-
'uname',
30-
'version',
31-
]
17+
'architecture',
18+
'linux_distribution',
19+
'mac_ver',
20+
'machine',
21+
'node',
22+
'platform',
23+
'processor',
24+
'python_build',
25+
'python_compiler',
26+
'python_version',
27+
'release',
28+
'system',
29+
'uname',
30+
'version',
31+
]
32+
3233

3334
class bcolors:
3435
HEADER = '\033[95m'
@@ -41,8 +42,7 @@ class bcolors:
4142
UNDERLINE = '\033[4m'
4243

4344

44-
4545
for key in profile:
46-
if hasattr(pl,key):
47-
print(key + bcolors.BOLD + ": "+ str(getattr(pl,key)())+ bcolors.ENDC)
48-
46+
if hasattr(pl, key):
47+
print(key + bcolors.BOLD + ": " + str(getattr(pl, key)()) + bcolors.ENDC)
48+

password_cracker.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@
2424
print 'Please install fcrypt if you are on Windows'
2525

2626

27-
28-
def testPass(cryptPass): # Start the function
27+
def testPass(cryptPass): # Start the function
2928
salt = cryptPass[0:2]
30-
dictFile=open('dictionary.txt','r') # Open the dictionary file
31-
for word in dictFile.readlines(): # Scan through the file
32-
word=word.strip('\n')
33-
cryptWord=crypt.crypt(word,salt) # Check for password in the file
29+
dictFile = open('dictionary.txt','r') # Open the dictionary file
30+
for word in dictFile.readlines(): # Scan through the file
31+
word = word.strip('\n')
32+
cryptWord = crypt.crypt(word, salt) # Check for password in the file
3433
if (cryptWord == cryptPass):
3534
print "[+] Found Password: "+word+"\n"
3635
return
3736
print "[-] Password Not Found.\n"
3837
return
3938

39+
4040
def main():
41-
passFile = open('passwords.txt') # Open the password file
42-
for line in passFile.readlines(): # Read through the file
41+
passFile = open('passwords.txt') # Open the password file
42+
for line in passFile.readlines(): # Read through the file
4343
if ":" in line:
44-
user=line.split(':')[0]
44+
user = line.split(':')[0]
4545
cryptPass = line.split(':')[1].strip(' ') # Prepare the user name etc
46-
print "[*] Cracking Password For: "+user
46+
print "[*] Cracking Password For: " + user
4747
testPass(cryptPass) # Call it to crack the users password
4848

4949
if __name__ == "__main__":

ping_servers.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
# Description : This script will, depending on the arguments supplied will ping the servers associated with that application group.
1010

11-
import os # Load the Library Module
12-
import subprocess # Load the Library Module
11+
import os # Load the Library Module
12+
import subprocess # Load the Library Module
1313
import sys # Load the Library Module
1414

1515
if '-h' in sys.argv or '--h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv: # Help Menu if called
@@ -47,18 +47,18 @@
4747

4848
filename = sys.argv[0] # Sets a variable for the script name
4949
logdir = os.getenv("logs") # Set the variable logdir by getting the OS environment logs
50-
logfile = 'ping_'+appgroup+'_'+site+'.log' # Set the variable logfile, using the arguments passed to create the logfile
51-
logfilename=os.path.join(logdir, logfile) # Set the variable logfilename by joining logdir and logfile together
50+
logfile = 'ping_' + appgroup + '_' + site + '.log' # Set the variable logfile, using the arguments passed to create the logfile
51+
logfilename = os.path.join(logdir, logfile) # Set the variable logfilename by joining logdir and logfile together
5252
confdir = os.getenv("my_config") # Set the variable confdir from the OS environment variable - 1.2
53-
conffile = (appgroup+'_servers_'+site+'.txt') # Set the variable conffile - 1.2
54-
conffilename=os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together - 1.2
53+
conffile = (appgroup + '_servers_' + site + '.txt') # Set the variable conffile - 1.2
54+
conffilename = os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together - 1.2
5555

5656
f = open(logfilename, "w") # Open a logfile to write out the output
5757
for server in open(conffilename): # Open the config file and read each line - 1.2
58-
ret = subprocess.call(myping + server, shell=True,stdout=f,stderr=subprocess.STDOUT) # Run the ping command for each server in the list.
58+
ret = subprocess.call(myping + server, shell=True, stdout=f, stderr=subprocess.STDOUT) # Run the ping command for each server in the list.
5959
if ret == 0: # Depending on the response
6060
f.write (server.strip() + " is alive" + "\n") # Write out that you can receive a reponse
6161
else:
6262
f.write (server.strip() + " did not respond" + "\n") # Write out you can't reach the box
6363

64-
print ("\n\tYou can see the results in the logfile : "+ logfilename); # Show the location of the logfile
64+
print ("\n\tYou can see the results in the logfile : " + logfilename); # Show the location of the logfile

ping_subnet.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Script Name : ping_subnet.py
22
# Author : Craig Richards
33
# Created : 12th January 2012
4-
# Last Modified :
4+
# Last Modified :
55
# Version : 1.0
66

7-
# Modifications :
7+
# Modifications :
88

99
# Description : After supplying the first 3 octets it will scan the final range for available addresses
1010

1111
import os # Load the Library Module
12-
import subprocess # Load the Library Module
12+
import subprocess # Load the Library Module
1313
import sys # Load the Library Module
1414

1515
filename = sys.argv[0] # Sets a variable for the script name
@@ -30,10 +30,11 @@
3030
elif os.name in ("nt", "dos", "ce"): # Check the os, if it's windows then
3131
myping = "ping -n 2 " # This is the ping command
3232

33-
f = open('ping_'+subnet+'.log', 'w') # Open a logfile
33+
f = open('ping_' + subnet + '.log', 'w') # Open a logfile
3434
for ip in range(2,255): # Set the ip variable for the range of numbers
35-
ret = subprocess.call(myping + str(subnet)+"."+str(ip) , shell=True,stdout=f,stderr=subprocess.STDOUT) # Run the command pinging the servers
35+
ret = subprocess.call(myping + str(subnet) + "." + str(ip) ,
36+
shell=True, stdout=f, stderr=subprocess.STDOUT) # Run the command pinging the servers
3637
if ret == 0: # Depending on the response
37-
f.write (subnet+"."+str(ip) + " is alive" + "\n") # Write out that you can receive a reponse
38+
f.write (subnet + "." + str(ip) + " is alive" + "\n") # Write out that you can receive a reponse
3839
else:
39-
f.write (subnet+"."+str(ip) + " did not respond" + "\n") # Write out you can't reach the box
40+
f.write (subnet + "." + str(ip) + " did not respond" + "\n") # Write out you can't reach the box

0 commit comments

Comments
 (0)