Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2ea2339

Browse files
Get Hash And File Type Script Added
1 parent d44f055 commit 2ea2339

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

‎Get Hash/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Generate Hash And File Type
2+
The python script generates the
3+
hash (MD5, SHA1, SHA256, SHA512, CRC32, ADLER32) of the
4+
file(s). Also, the file type of the file(s)
5+
6+
What the program does?
7+
- Can take multiple files at the same time
8+
- Generate the hashes
9+
- Can display only file type of file(s)
10+
11+
12+
### Requirements
13+
>Python3.6+
14+
>
15+
> pip install -r requirements.txt
16+
17+
18+
### Usage
19+
```
20+
hash.py [-h] -f FILE [FILE ...] [-t]
21+
22+
Get The Hashes And File Type Of File(s)
23+
24+
optional arguments:
25+
-h, --help show this help message and exit
26+
-f FILE [FILE ...] Submit file(s)
27+
-t Get only the file type of file(s)
28+
```
29+
30+
### Contribution
31+
Any kind of contributions are welcome
32+
1. Fork the project
33+
2. Commit your changes
34+
3. Open a pull request
35+
36+

‎Get Hash/hash.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import argparse
2+
from filehash import FileHash
3+
import magic
4+
import os
5+
6+
7+
def file_type_hashes(files):
8+
# Declare the type of hash you want
9+
md5Hash = FileHash('md5')
10+
sha1Hash = FileHash('sha1')
11+
sha256Hash = FileHash('sha256')
12+
sha512Hash = FileHash('sha512')
13+
crcHash = FileHash('crc32')
14+
adler32Hash = FileHash('adler32')
15+
16+
# Iterate through the files
17+
for file in files:
18+
19+
# Check if file exists
20+
if os.path.isfile(file):
21+
22+
# Generate the file hash and the file type as well
23+
file_info = {
24+
"filename": file,
25+
"filetype": magic.from_file(file),
26+
"md5": md5Hash.hash_file(file),
27+
"sha1": sha1Hash.hash_file(file),
28+
"sha256": sha256Hash.hash_file(file),
29+
"sha512": sha512Hash.hash_file(file),
30+
"crc32": crcHash.hash_file(file),
31+
"adler32": adler32Hash.hash_file(file)
32+
}
33+
34+
print(file_info)
35+
36+
else:
37+
print(f"No File Found: {file}")
38+
39+
40+
def file_type(files):
41+
42+
# Iterate through the files
43+
for file in files:
44+
45+
# Check if file exists
46+
if os.path.isfile(file):
47+
48+
# Generate the file type
49+
print(f"Filename: {file} , File Type: {magic.from_file(file)}")
50+
51+
else:
52+
print(f"No File Found: {file}")
53+
54+
55+
def main():
56+
parser = argparse.ArgumentParser(description='Get The Hashes And File Type Of File(s)')
57+
58+
# Argument is to accept a file(s)
59+
parser.add_argument('-f', dest='file', nargs='+', type=str, help='Submit file(s)', required=True)
60+
61+
# Argument is to display only the file type of file(s)
62+
parser.add_argument('-t', dest='type', action='store_true', help='Get only the file type of file(s)')
63+
64+
args = parser.parse_args()
65+
66+
if args.file:
67+
# Accepts files
68+
files = args.file
69+
70+
if files:
71+
# Display the file type only
72+
if args.type:
73+
file_type(files)
74+
75+
# Show the hashes and the file type as well
76+
else:
77+
file_type_hashes(files)
78+
79+
80+
if __name__ == '__main__':
81+
main()

‎Get Hash/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
filehash==0.1.dev5
2+
python-magic-bin==0.4.14

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /