-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
ReloadCam_Helper.py
203 lines (151 loc) · 5.83 KB
/
ReloadCam_Helper.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Refrescador automatico de clines
#Creado por Dagger - https://github.com/gavazquez
import ReloadCam_Arguments
def GetVersion():
return 23
cryptoKey = "1234CAMreload"
currentIpAddress = "0"
#Encriptamos las webs por si los administradores de esas webs se ponen a buscar su propio codigo...
#NO ES UNA ENCRIPTACION MUY SEGURA! Es un simple Vigenere
def Encrypt(clearText):
import base64
encriptedText = []
for i in range(len(clearText)):
keyChar = cryptoKey[i % len(cryptoKey)]
encriptedChar = chr((ord(clearText[i]) + ord(keyChar)) % 256)
encriptedText.append(encriptedChar)
return base64.urlsafe_b64encode("".join(encriptedText))
#Encriptamos las webs por si los administradores de esas webs se ponen a buscar su propio codigo...
#NO ES UNA ENCRIPTACION MUY SEGURA! Es un simple Vigenere
def Decrypt(encriptedText):
import base64
decryptedText = []
encriptedText = base64.urlsafe_b64decode(encriptedText)
for i in range(len(encriptedText)):
keyChar = cryptoKey[i % len(cryptoKey)]
decryptedChar = chr((256 + ord(encriptedText[i]) - ord(keyChar)) % 256)
decryptedText.append(decryptedChar)
return "".join(decryptedText)
def GetMyIP():
import urllib2, re
global currentIpAddress
if currentIpAddress == '0':
currentIpAddress = TryGetIpAddress("http://ip.42.pl/raw", '(\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3})', 5)
if currentIpAddress == '0':
currentIpAddress = TryGetIpAddress("http://jsonip.com", '(\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3})', 5)
if currentIpAddress == '0':
currentIpAddress = TryGetIpAddress("http://ip.jsontest.com/", '([0-9.]*)', 5)
if currentIpAddress == '0':
currentIpAddress = TryGetIpAddress("http://httpbin.org/ip", '(\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3})', 5)
if currentIpAddress == '0':
currentIpAddress = TryGetIpAddress("https://api.ipify.org/", '(\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3})', 5)
if currentIpAddress == '0':
currentIpAddress = TryGetIpAddress("http://checkip.dyndns.org", '(\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3})', 15)
return currentIpAddress
def TryGetIpAddress(url, regex, timeout):
import urllib2, re
try:
return re.search(regex, urllib2.urlopen(url, timeout=5).read()).group(1)
except:
return ""
def GetRandomString(length):
import random, string
return ''.join(random.choice(string.lowercase) for i in range(length))
def GetHtmlCode(headers, url):
import urllib, urllib2, cookielib
cookieJar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar))
if headers is not None and len(headers) > 0:
opener.addheaders = headers
try:
htmlCode = opener.open(url, timeout=5).read()
if htmlCode == '': raise Exception('No HTMLCode')
except:
print "Could not open website! (No internet connection or bad URL: " + url + ")"
return '';
return htmlCode;
def GetPostHtmlCode(data, headers, url):
import urllib, urllib2, cookielib
encodedData = urllib.urlencode(data)
# Send HTTP POST request
req = urllib2.Request(url, encodedData)
if headers is not None:
for key in headers.keys():
req.add_header(key, headers[key])
try:
response = urllib2.urlopen(req, timeout=5)
htmlCode = response.read()
if htmlCode == '': raise Exception('No HTMLCode')
except:
print "Could not open website! (No internet connection or bad URL: " + url + ")"
return '';
return htmlCode;
def FindStandardClineInText(text):
return FindClineInText(text, "([CN]:\s*\S+\s+\d+\s+\S+\s+[\w./\-]+)");
def CleanHtml(raw_html):
import re
cleanr = re.compile('<.*?>')
cleantext = re.sub(cleanr, '', raw_html)
return cleantext
def FindClineInText(text, regex):
import re
regExpr = re.compile(regex)
match = regExpr.search(text)
if match is None:
return None;
cline = match.group(1)
return cline;
def TestCline(cline):
if PingCline(cline) == 9999:
print "Cline: '" + cline + "' did not pass validation. (No ping)"
return False
clineValid = TestClineTimeout(cline, 15)
if clineValid is False:
print "Cline: '" + cline + "' did not pass validation. (user/pass invalid or timeout)"
return clineValid
def TestClineTimeout(cline, timeout):
import socket, re, sys, ReloadCam_ClineTester, ReloadCam_NlineTester
regExpr = re.compile('[C].*')
match = regExpr.search(cline)
if match is None:
regExpr = re.compile('[N].*')
match = regExpr.search(cline)
if match is not None:
return ReloadCam_NlineTester.TestNline(cline,timeout)
return False
else:
return ReloadCam_ClineTester.TestCline(cline,timeout)
def SortClinesByPing(clines):
clines_ping = []
for cline in clines:
clines_ping.append([cline, PingCline(cline)])
clines_ping = sorted(clines_ping, key=lambda cline: cline[1]) # sort by ping
return [x[0] for x in clines_ping]
def PingCline(cline):
import re, socket
regExpr = re.compile('[CN]:\s+(\S+)+\s+(\d*)')
match = regExpr.search(cline)
if match is None:
return 9999;
try:
ip = socket.gethostbyname(match.group(1))
return Ping(ip)
except:
return 9999;
def Ping(host):
import subprocess,platform,os,re
ping = subprocess.Popen(
["ping", "-n" if platform.system().lower()=="windows" else "-c", "1", host],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE
)
out, error = ping.communicate()
if error is None or error == "":
regExpr = re.compile('time=(\d+\.?\d*)')
match = regExpr.search(out)
if match is None:
return 9999;
return match.group(1)
return 9999;