forked from tinseldev/shocator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
106 lines (96 loc) · 3.51 KB
/
utils.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import subprocess
import random
import re
import os
import time
def randomizer():
with open('cities.txt', 'r') as f:
citystr = random.choice(f.readlines())
return citystr.replace('\n', '').replace(' ', '-').replace(
'`', '').replace("'", '')
def downloader(city):
process = subprocess.run(f'shodan download --limit -1 -- '
f'{city.lower()}-data.json.gz '
f'screenshot.label:webcam city:{city.lower()} '
f'-port:5900,5901,5910,3389,3388',
shell=True, capture_output=True, text=True).stdout
try:
res_count = re.split('Saved', process)[1]
c = []
for _ in res_count:
if _.isdigit():
c.append(_)
res_count = [str(integer) for integer in c]
a_string = "".join(res_count)
res_count = int(a_string)
if res_count == 0:
os.system('rm -f *-data.json.gz')
except IndexError:
res_count = 0
return res_count
def error_parser(error):
try:
seconds = re.split('in', error)[1]
c = []
for _ in seconds:
if _.isdigit():
c.append(_)
seconds = [str(integer) for integer in c]
a_string = "".join(seconds)[:-1]
seconds = int(a_string)
except IndexError:
error = 'Parser error'
return seconds
def jpg_poster(pbar, file, bot, id, country, city, show):
success = False
retry = 0
ip = os.path.splitext(os.path.basename(file))[0]
while not success:
try:
pbar.write('Trying to send a post...')
with open(os.path.join('snapshots', file), 'rb') as f:
bot.sendPhoto(chat_id=id, photo=f, caption=f"Location: "
f"{country}, {city}\n{ip if show else ''}",
disable_notification=True, timeout=250)
success = True
pbar.update(1)
pbar.write('Post sended')
time.sleep(4)
except Exception as error:
if retry > 4:
pbar.write('Failed to send a post')
break
else:
retry += 1
error = str(error)
pbar.write('Flood control exceeded')
seconds = error_parser(error)
pbar.write(f'Sleeping for {seconds} seconds...')
time.sleep(seconds)
def gif_poster(pbar, file, bot, id, country, city, show):
success = False
retry = 0
ip = os.path.splitext(os.path.basename(file))[0]
while not success:
try:
pbar.write('Trying to send a post...')
with open(os.path.join('snapshots', file), 'rb') as f:
bot.sendAnimation(chat_id=id, animation=f,
caption=f"Location: "
f"{country}, {city}\n{ip if show else ''}",
disable_notification=True, timeout=250)
success = True
pbar.update(1)
pbar.write('Post sended')
time.sleep(4)
except Exception as error:
if retry > 4:
pbar.write('Failed to send a post')
break
else:
retry += 1
error = str(error)
pbar.write('Flood control exceeded')
seconds = error_parser(error)
pbar.write(f'Sleeping for {seconds} seconds...')
time.sleep(seconds)