forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_file.py
37 lines (30 loc) · 1.09 KB
/
check_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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()