Speedo0o commited on
Commit
7683dd1
·
verified ·
1 Parent(s): 9e1ea83

Create 1.py

Browse files
Files changed (1) hide show
  1. 1.py +426 -0
1.py ADDED
@@ -0,0 +1,426 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ import random
4
+ import psutil
5
+ import traceback
6
+ import subprocess
7
+ import sys
8
+ import requests
9
+ import string
10
+ import ctypes
11
+ import ctypes.wintypes
12
+
13
+ try:
14
+ import pyautogui
15
+ pyautogui.FAILSAFE = False
16
+ except ImportError:
17
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "pyautogui", "opencv-python"])
18
+ import pyautogui
19
+ pyautogui.FAILSAFE = False
20
+
21
+ from pywinauto.application import Application
22
+ from pywinauto.findwindows import WindowNotFoundError
23
+
24
+ # ==========================================
25
+ # إعدادات TuxlerVPN
26
+ # ==========================================
27
+ TUXLER_EXE_PATH = r"C:\Program Files (x86)\tuxlerVPN\tuxlerVPN.exe"
28
+ TUXLER_WINDOW_TITLE = "Tuxler"
29
+ TUXLER_PROCESS_NAME = "tuxlerVPN.exe"
30
+
31
+ ONOFF_OFFSET_FROM_RIGHT = 120
32
+ ONOFF_OFFSET_FROM_TOP = 180
33
+
34
+ COUNTRY_MENU_OFFSET_RIGHT = 190
35
+ COUNTRY_MENU_OFFSET_TOP = 380
36
+ COUNTRY_MENU_DROP_Y = 30
37
+
38
+ COUNTRY_FILE = "country.txt"
39
+ BLOCKED_COUNTRIES = ["1"]
40
+
41
+ # عدد الفشل المتتالي قبل تشغيل سكربت الطوارئ (تم التعديل إلى 2)
42
+ FAIL_THRESHOLD = 2
43
+ # اسم سكربت الطوارئ (تم التعديل إلى rest.py)
44
+ EMERGENCY_SCRIPT = "rest.py"
45
+
46
+ # ==========================================
47
+ # دوال Windows API لإجبار النافذة للأمام
48
+ # ==========================================
49
+ user32 = ctypes.windll.user32
50
+
51
+ SW_RESTORE = 9
52
+ SW_SHOW = 5
53
+ SW_MAXIMIZE = 3
54
+
55
+ HWND_TOPMOST = -1
56
+ HWND_NOTOPMOST = 0
57
+ SWP_NOSIZE = 0x0001
58
+ SWP_NOMOVE = 0x0002
59
+ SWP_SHOWWINDOW = 0x0040
60
+
61
+ def force_window_to_front(hwnd):
62
+ """
63
+ يجبر النافذة على الظهور في الأمام بطريقة قوية
64
+ باستخدام Win32 API مباشرة لتجاوز قيود Windows
65
+ """
66
+ if not hwnd:
67
+ return False
68
+ try:
69
+ # تأكد أن النافذة مرئية ومفعلة
70
+ user32.ShowWindow(hwnd, SW_RESTORE)
71
+ time.sleep(0.2)
72
+
73
+ # استخدام trick معروفة: نقل النافذة لـ Topmost ثم إعادتها
74
+ user32.SetWindowPos(hwnd, HWND_TOPMOST,
75
+ 0, 0, 0, 0,
76
+ SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW)
77
+ time.sleep(0.1)
78
+ user32.SetWindowPos(hwnd, HWND_NOTOPMOST,
79
+ 0, 0, 0, 0,
80
+ SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW)
81
+ time.sleep(0.1)
82
+
83
+ # محاولة إرسال رسالة تفعيل
84
+ foreground = user32.GetForegroundWindow()
85
+ if foreground != hwnd:
86
+ # الطريقة الفعّالة لنقل الـ focus
87
+ foreground_thread = user32.GetWindowThreadProcessId(foreground, None)
88
+ hwnd_thread = user32.GetWindowThreadProcessId(hwnd, None)
89
+ ctypes.windll.kernel32.AttachThreadInput(foreground_thread, hwnd_thread, True)
90
+ user32.SetForegroundWindow(hwnd)
91
+ ctypes.windll.kernel32.AttachThreadInput(foreground_thread, hwnd_thread, False)
92
+ else:
93
+ user32.SetForegroundWindow(hwnd)
94
+
95
+ user32.ShowWindow(hwnd, SW_SHOW)
96
+ time.sleep(0.3)
97
+ return True
98
+ except Exception as e:
99
+ print(f"⚠️ force_window_to_front error: {e}")
100
+ return False
101
+
102
+ # ==========================================
103
+ # دوال إدارة ملف الدولة
104
+ # ==========================================
105
+ def get_last_country():
106
+ if os.path.exists(COUNTRY_FILE):
107
+ with open(COUNTRY_FILE, "r", encoding="utf-8") as f:
108
+ country = f.read().strip()
109
+ if country:
110
+ return country
111
+ return "A"
112
+
113
+ def save_last_country(country_name):
114
+ try:
115
+ with open(COUNTRY_FILE, "w", encoding="utf-8") as f:
116
+ f.write(country_name)
117
+ print(f"[+] Saved '{country_name}' to {COUNTRY_FILE}")
118
+ except Exception as e:
119
+ print(f"[-] Error saving country to file: {e}")
120
+
121
+ def perform_smart_scroll(last_country):
122
+ start_letter = last_country[0].upper() if last_country else 'A'
123
+ if not start_letter.isalpha():
124
+ start_letter = 'A'
125
+ target_letter = random.choice(string.ascii_uppercase)
126
+ start_idx = ord(start_letter) - 65
127
+ target_idx = ord(target_letter) - 65
128
+ diff = start_idx - target_idx
129
+ scroll_amount = diff * 600 + random.randint(-40, 40)
130
+ if diff == 0:
131
+ scroll_amount = random.choice([-40, 40])
132
+ print(f"🤖 [Smart Scroll] '{last_country}'({start_letter}) -> '{target_letter}' | Scroll: {scroll_amount}")
133
+ if scroll_amount != 0:
134
+ steps = max(1, abs(scroll_amount) // 100)
135
+ step_val = scroll_amount // steps
136
+ for _ in range(steps):
137
+ pyautogui.scroll(step_val)
138
+ time.sleep(0.0005)
139
+
140
+ # ==========================================
141
+ # فحص الـ IP
142
+ # ==========================================
143
+ def get_current_ip_info(label=""):
144
+ """يُرجع dict يحتوي ip و country، أو None عند الفشل"""
145
+ tag = f"[{label}] " if label else ""
146
+ print(f"{tag}Checking current IP...")
147
+ for attempt in range(3):
148
+ try:
149
+ r = requests.get("http://ip-api.com/json/", timeout=10)
150
+ if r.status_code == 200:
151
+ data = r.json()
152
+ ip = data.get("query", "Unknown")
153
+ country = data.get("country", "Unknown")
154
+ print(f"{tag}IP: {ip} | Country: {country}")
155
+ return {"ip": ip, "country": country}
156
+ except Exception as e:
157
+ print(f"{tag}Attempt {attempt+1} failed: {e}")
158
+ time.sleep(2)
159
+ print(f"{tag}Could not retrieve IP info.")
160
+ return None
161
+
162
+ # ==========================================
163
+ # إدارة البرنامج
164
+ # ==========================================
165
+ def close_application_if_running():
166
+ print(f"Closing {TUXLER_PROCESS_NAME} if running...")
167
+ for proc in psutil.process_iter(['pid', 'name']):
168
+ if proc.info['name'] and proc.info['name'].lower() == TUXLER_PROCESS_NAME.lower():
169
+ try:
170
+ proc.kill()
171
+ time.sleep(1)
172
+ except:
173
+ pass
174
+
175
+ def launch_application(timeout=90):
176
+ close_application_if_running()
177
+ time.sleep(3)
178
+ try:
179
+ app = Application(backend="uia").start(TUXLER_EXE_PATH, timeout=timeout)
180
+ main_window = None
181
+ for attempt in range(15):
182
+ try:
183
+ main_window = app.window(title=TUXLER_WINDOW_TITLE)
184
+ main_window.wait('visible', timeout=10)
185
+ print(f"✅ Window found on attempt {attempt+1}")
186
+ break
187
+ except:
188
+ time.sleep(2)
189
+
190
+ if not main_window:
191
+ print("❌ Could not find window.")
192
+ return None, None
193
+
194
+ # جلب الـ HWND الحقيقي
195
+ try:
196
+ hwnd = main_window.wrapper_object().handle
197
+ except:
198
+ hwnd = None
199
+
200
+ # إجبار النافذة للأمام فقط بدون تغيير الحجم
201
+ if hwnd:
202
+ force_window_to_front(hwnd)
203
+ else:
204
+ try:
205
+ main_window.wrapper_object().set_focus()
206
+ except:
207
+ pass
208
+
209
+ time.sleep(2)
210
+
211
+ # التحقق مرة ثانية أن النافذة في الأمام
212
+ if hwnd:
213
+ force_window_to_front(hwnd)
214
+
215
+ return app, main_window
216
+
217
+ except Exception as e:
218
+ print(f"Failed to launch: {e}")
219
+ return None, None
220
+
221
+ import win32api
222
+ import win32con
223
+ import win32gui
224
+
225
+ def click_at_hwnd(hwnd, offset_x, offset_y):
226
+ """
227
+ ينقر على إحداثيات داخل النافذة مباشرة عبر WM_LBUTTONDOWN/UP
228
+ يعمل حتى بدون شاشة أو في RDP
229
+ """
230
+ lparam = win32api.MAKELONG(offset_x, offset_y)
231
+ win32gui.PostMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lparam)
232
+ time.sleep(0.1)
233
+ win32gui.PostMessage(hwnd, win32con.WM_LBUTTONUP, 0, lparam)
234
+ time.sleep(0.3)
235
+
236
+ def scroll_at_hwnd(hwnd, offset_x, offset_y, scroll_amount):
237
+ """
238
+ يرسل WM_MOUSEWHEEL مباشرة للنافذة
239
+ """
240
+ # WM_MOUSEWHEEL يحتاج إحداثيات الشاشة الكاملة
241
+ rect = win32gui.GetWindowRect(hwnd)
242
+ screen_x = rect[0] + offset_x
243
+ screen_y = rect[1] + offset_y
244
+ lparam = win32api.MAKELONG(screen_x, screen_y)
245
+
246
+ WHEEL_DELTA = 120
247
+ steps = abs(scroll_amount) // WHEEL_DELTA
248
+ direction = 1 if scroll_amount > 0 else -1
249
+
250
+ for _ in range(steps):
251
+ wparam = win32api.MAKELONG(0, direction * WHEEL_DELTA)
252
+ win32gui.PostMessage(hwnd, win32con.WM_MOUSEWHEEL, wparam, lparam)
253
+ time.sleep(0.05)
254
+
255
+ def interact_with_ui(main_window):
256
+ try:
257
+ hwnd = main_window.wrapper_object().handle
258
+ force_window_to_front(hwnd)
259
+ time.sleep(0.5)
260
+
261
+ rect = main_window.rectangle()
262
+ win_w = rect.right - rect.left
263
+ win_h = rect.bottom - rect.top
264
+
265
+ # حساب الإحداثيات النسبية داخل النافذة
266
+ onoff_x = win_w - ONOFF_OFFSET_FROM_RIGHT
267
+ onoff_y = ONOFF_OFFSET_FROM_TOP
268
+
269
+ menu_x = win_w - COUNTRY_MENU_OFFSET_RIGHT
270
+ menu_y = COUNTRY_MENU_OFFSET_TOP
271
+ list_y = menu_y + COUNTRY_MENU_DROP_Y
272
+
273
+ print(f"👉 Clicking ON/OFF at offset ({onoff_x}, {onoff_y})")
274
+ click_at_hwnd(hwnd, onoff_x, onoff_y)
275
+ time.sleep(1.5)
276
+
277
+ print(f"🌍 Opening Country Menu at offset ({menu_x}, {menu_y})")
278
+ click_at_hwnd(hwnd, menu_x, menu_y)
279
+ time.sleep(1)
280
+
281
+ print(f"👇 Moving to list at ({menu_x}, {list_y})")
282
+ # إرسال WM_MOUSEMOVE لتفعيل الـ hover
283
+ lparam_list = win32api.MAKELONG(menu_x, list_y)
284
+ win32gui.PostMessage(hwnd, win32con.WM_MOUSEMOVE, 0, lparam_list)
285
+ time.sleep(0.5)
286
+
287
+ last_country = get_last_country()
288
+ start_letter = last_country[0].upper() if last_country else 'A'
289
+ target_letter = random.choice(string.ascii_uppercase)
290
+ diff = (ord(start_letter) - 65) - (ord(target_letter) - 65)
291
+ scroll_ticks = diff * 3 # عدد ticks (كل tick = 120)
292
+
293
+ print(f"🤖 Scrolling {scroll_ticks} ticks")
294
+ scroll_at_hwnd(hwnd, menu_x, list_y, scroll_ticks * 120)
295
+ time.sleep(0.5)
296
+
297
+ print("🎯 Clicking to select country...")
298
+ click_at_hwnd(hwnd, menu_x, list_y)
299
+
300
+ return True
301
+
302
+ except Exception as e:
303
+ print(f"** Error during UI interaction: {e}")
304
+ traceback.print_exc()
305
+ return False
306
+
307
+ # ==========================================
308
+ # تشغيل سكربت الطوارئ
309
+ # ==========================================
310
+ def run_emergency_script():
311
+ print(f"\n🚨 Running emergency script: {EMERGENCY_SCRIPT}")
312
+ if not os.path.exists(EMERGENCY_SCRIPT):
313
+ print(f"❌ {EMERGENCY_SCRIPT} not found!")
314
+ return False
315
+ try:
316
+ result = subprocess.run([sys.executable, EMERGENCY_SCRIPT], timeout=120)
317
+ print(f"Emergency script exited with code: {result.returncode}")
318
+ return result.returncode == 0
319
+ except subprocess.TimeoutExpired:
320
+ print("⚠️ Emergency script timed out.")
321
+ return False
322
+ except Exception as e:
323
+ print(f"❌ Error running emergency script: {e}")
324
+ return False
325
+
326
+ # ==========================================
327
+ # الدالة الرئيسية
328
+ # ==========================================
329
+ def restart_and_connect():
330
+ print("\n" + "="*50)
331
+ print("Restarting TuxlerVPN...")
332
+ print("="*50)
333
+ app, main_window = launch_application(timeout=90)
334
+ if not app or not main_window:
335
+ return False
336
+ try:
337
+ time.sleep(10 + random.uniform(0, 3))
338
+ # إعادة جلب النافذة للأمام مرة أخرى قبل التفاعل
339
+ try:
340
+ hwnd = main_window.wrapper_object().handle
341
+ force_window_to_front(hwnd)
342
+ except:
343
+ pass
344
+ time.sleep(1)
345
+ return interact_with_ui(main_window)
346
+ except:
347
+ return False
348
+
349
+
350
+ if __name__ == "__main__":
351
+ print("🚀 TuxlerVPN Advanced Automation — IP-Change Guaranteed Mode")
352
+ print("="*50)
353
+
354
+ # ─── قراءة الـ IP قبل أي شيء ───
355
+ pre_info = get_current_ip_info("BEFORE")
356
+ if pre_info:
357
+ original_ip = pre_info["ip"]
358
+ else:
359
+ original_ip = None
360
+ print("⚠️ Could not read IP before start. Will compare only by country.")
361
+
362
+ max_retries = 50 # حد أقصى لعدد المحاولات الكلية
363
+ consecutive_fail = 0 # عداد الفشل المتتالي
364
+ attempts = 0
365
+ success = False
366
+
367
+ while attempts < max_retries:
368
+ attempts += 1
369
+ print(f"\n{'='*50}")
370
+ print(f"--- Attempt {attempts} of {max_retries} ---")
371
+
372
+ # ─── تشغيل الفشل المتتالي يطلق السكربت الطارئ ───
373
+ if consecutive_fail >= FAIL_THRESHOLD:
374
+ print(f"⚠️ {consecutive_fail} consecutive failures! Launching {EMERGENCY_SCRIPT}...")
375
+ run_emergency_script()
376
+ consecutive_fail = 0 # إعادة العداد بعد التدخل الطارئ
377
+ print("⏳ Waiting 5s after emergency script...")
378
+ time.sleep(5) # الانتظار 5 ثوانٍ بعد الفشل
379
+ continue
380
+
381
+ if restart_and_connect():
382
+ print("⏳ Waiting 15s for VPN to establish...")
383
+ time.sleep(15)
384
+
385
+ post_info = get_current_ip_info("AFTER")
386
+
387
+ if post_info is None:
388
+ print("⚠️ Could not read IP after connection. Retrying...")
389
+ consecutive_fail += 1
390
+ continue
391
+
392
+ new_ip = post_info["ip"]
393
+ new_country = post_info["country"]
394
+
395
+ # ─── فحص تغيير الـ IP ───
396
+ ip_changed = (original_ip is None) or (new_ip != original_ip)
397
+
398
+ if not ip_changed:
399
+ print(f"🔁 IP did NOT change (still {new_ip}). Retrying...")
400
+ consecutive_fail += 1
401
+ continue
402
+
403
+ # ─── فحص الدولة المحظورة ───
404
+ if new_country in BLOCKED_COUNTRIES:
405
+ print(f"⚠️ Connected to BLOCKED country: {new_country}. Retrying...")
406
+ consecutive_fail += 1
407
+ continue
408
+
409
+ # ─── نجاح ───
410
+ print(f"✅ IP changed: {original_ip} → {new_ip} | Country: {new_country}")
411
+ save_last_country(new_country)
412
+ consecutive_fail = 0
413
+ success = True
414
+ break
415
+
416
+ else:
417
+ print("❌ UI interaction failed. Retrying...")
418
+ consecutive_fail += 1
419
+ time.sleep(5)
420
+
421
+ print("\n" + "="*50)
422
+ if success:
423
+ print("🎉 Script completed successfully — IP has changed!")
424
+ else:
425
+ print("❌ Script failed after maximum retries.")
426
+ print("="*50)