#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ =============================================================================== NP Proxy — MB Check Bot (document + full source) =============================================================================== একটা প্রোক্সি লাইন (HOST:PORT:USER:PASS) দিয়ে দেখাবে: • কত MB ব্যবহার হয়েছে • কত MB বাকি আছে (এবং শতাংশ) • লাইন কত মিনিট / কত দিন বাকি • লাইন এখন চালু না বন্ধ (active / used_up / expired / disabled) • চাইলে আসল exit IP ও দেশ যাচাই করে (--verify-exit) Python 3.8+ · শুধু standard library · কোনো pip install লাগে না। ------------------------------------------------------------------------------- ১. দ্রুত ব্যবহার ------------------------------------------------------------------------------- python3 mb-check-bot.py "proxy.npproxy.shop:24442:HBr151py6_country-US_session-8f11f143_lifetime-30:YOUR_PASSWORD" python3 mb-check-bot.py --user h143 --pass YOUR_PASSWORD --country DE python3 mb-check-bot.py "host:port:user:pass" --verify-exit # আসল IP যাচাই python3 mb-check-bot.py "host:port:user:pass" --json # JSON আউটপুট python3 mb-check-bot.py "host:port:user:pass" --watch 60 # প্রতি ৬০ সেকেন্ডে python3 mb-check-bot.py --file lines.txt # একসাথে অনেক লাইন exit code: 0 = লাইন চালু · 1 = বন্ধ/শেষ · 2 = ভুল তথ্য বা নেটওয়ার্ক সমস্যা ------------------------------------------------------------------------------- ২. MB হিসাবের সূত্র (formula) — সার্ভার ঠিক এইভাবেই হিসাব করে ------------------------------------------------------------------------------- 1 MB = 1,048,576 bytes (1 MiB, বাইনারি) 1 GB = 1,073,741,824 bytes usedMB = usedBytes / 1048576 totalMB = limitBytes / 1048576 (0 হলে = আনলিমিটেড) — টোটাল কোটা leftBytes = max(0, limitBytes - usedBytes) leftMB = leftBytes / 1048576 usedPercent = min(100, usedBytes / limitBytes * 100) (১ দশমিক ঘর) daysLeft = ceil((expiresAt - now) / 86_400_000 ms) লাইন কখন বন্ধ হয় (state): used_up → leftBytes <= 0 (ঠিক ১ বাইটও বাকি নেই) expired → now >= expiresAt disabled → অ্যাডমিন হাতে বন্ধ করেছে active → উপরের কোনোটাই নয় ⚠️ কোটা বাইট-লেভেলে গোনা হয়: কোটা শেষ হওয়ার সাথে সাথেই লাইন কেটে যায়, এক বাইটও বেশি যায় না। ------------------------------------------------------------------------------- ৩. কোন API ব্যবহার করে ------------------------------------------------------------------------------- POST {API}/api/check {"line": "host:port:user:pass"} GET {API}/api/check?line=host:port:user:pass → {"valid":true,"type":"member","country":"DE","username":"h143", "usedMB":720.07,"limitMB":0,"leftMB":null,"unlimited":true, "usedPercent":null,"state":"active","expiresAt":"...","minutesLeft":...} (এই endpoint পাবলিক — শুধু নিজের লাইনের তথ্য দেয়, পাসওয়ার্ড কখনো ফেরত দেয় না।) =============================================================================== """ import argparse import json import math import re import sys import time import urllib.error import urllib.parse import urllib.request API_DEFAULT = "https://www.npproxy.shop" TIMEOUT = 15 # ── রঙ (Windows/পুরনো টার্মিনালেও কাজ করে; --no-color দিলে বন্ধ) ────────────── class C: on = sys.stdout.isatty() @classmethod def w(cls, code, text): return f"\033[{code}m{text}\033[0m" if cls.on else str(text) @classmethod def g(cls, t): return cls.w("32", t) @classmethod def y(cls, t): return cls.w("33", t) @classmethod def r(cls, t): return cls.w("31", t) @classmethod def b(cls, t): return cls.w("36", t) @classmethod def d(cls, t): return cls.w("90", t) @classmethod def bold(cls, t): return cls.w("1", t) # ──────────────────────────────────────────────────────────────────────────── # ১) লাইন পার্স করা — host:port:user:pass # ──────────────────────────────────────────────────────────────────────────── def parse_line(line): """'host:port:user:pass' → dict, নাহলে None। পাসওয়ার্ডে ':' থাকলে সেটাও ঠিকভাবে ধরা পড়ে (শেষ অংশটাই পাসওয়ার্ড)।""" if not line: return None raw = str(line).strip().strip('"').strip("'") parts = raw.split(":") if len(parts) < 4: return None host, port, user = parts[0].strip(), parts[1].strip(), parts[2].strip() password = ":".join(parts[3:]).strip() if not host or not port.isdigit() or not user or not password: return None return {"host": host, "port": int(port), "user": user, "pass": password} def country_from_user(user): """ইউজারনেম থেকে দেশ বের করা — HBr151py6_country-US_session-8f11f143_lifetime-30 → DE""" m = re.search(r"[_-]country-([A-Za-z]{2})\b", user or "") return m.group(1).upper() if m else None # ──────────────────────────────────────────────────────────────────────────── # ২) সার্ভারের কাছে MB জিজ্ঞেস করা # ──────────────────────────────────────────────────────────────────────────── def fetch_info(line, api=API_DEFAULT, timeout=TIMEOUT): """{api}/api/check-এ লাইন পাঠিয়ে পুরো তথ্য নিয়ে আসে (dict)।""" body = json.dumps({"line": line}).encode() req = urllib.request.Request( api.rstrip("/") + "/api/check", data=body, method="POST", headers={"Content-Type": "application/json", "User-Agent": "NP-MBCheckBot/1.0", "Accept": "application/json"}, ) with urllib.request.urlopen(req, timeout=timeout) as r: return json.loads(r.read().decode("utf-8", "replace")) # ──────────────────────────────────────────────────────────────────────────── # ৩) হিসাব (formula) — একই সংখ্যা ক্লায়েন্টেও মিলিয়ে দেখা # ──────────────────────────────────────────────────────────────────────────── MB = 1048576 GB = 1073741824 def calc(info): used = info.get("usedBytes") or 0 limit = info.get("limitBytes") or 0 unlimited = bool(info.get("unlimited")) or limit <= 0 left = None if unlimited else max(0, limit - used) pct = None if unlimited else min(100.0, round(used / limit * 1000) / 10.0) exp = info.get("expiresAt") days_left = None if exp: try: t = time.mktime(time.strptime(exp[:19], "%Y-%m-%dT%H:%M:%S")) days_left = max(0, math.ceil((t - time.time()) / 86400)) except Exception: days_left = None return { "usedMB": round(used / MB, 2), "limitMB": None if unlimited else round(limit / MB, 2), "leftMB": None if left is None else round(left / MB, 2), "usedPercent": pct, "unlimited": unlimited, "leftBytes": left, "daysLeft": days_left, } def bar(pct, width=24): """শতাংশের গ্রাফ — [██████·····] 42.5%""" if pct is None: return "[" + "─" * width + "] unlimited" filled = int(round(width * pct / 100.0)) filled = max(0, min(width, filled)) return "[" + "█" * filled + "·" * (width - filled) + "] %.1f%%" % pct # ──────────────────────────────────────────────────────────────────────────── # ৪) (ঐচ্ছিক) আসল exit IP ও দেশ যাচাই — প্রক্সি দিয়েই রিকোয়েস্ট # ──────────────────────────────────────────────────────────────────────────── def verify_exit(line, timeout=TIMEOUT): """প্রক্সির ভেতর দিয়ে ip-api.com-এ গিয়ে আসল exit IP/দেশ দেখে। মনে রাখুন: এটা ইন্টারনেটে যাওয়ার সময় সত্যিই কোন দেশ থেকে বেরোচ্ছে তার প্রমাণ।""" p = parse_line(line) if not p: return {"ok": False, "error": "bad line"} url = "http://ip-api.com/json/?fields=status,country,countryCode,query,timezone" pwd = urllib.parse.quote(p["pass"], safe="") usr = urllib.parse.quote(p["user"], safe="") proxy = f"http://{usr}:{pwd}@{p['host']}:{p['port']}" opener = urllib.request.build_opener( urllib.request.ProxyHandler({"http": proxy, "https": proxy}) ) t0 = time.time() try: with opener.open(url, timeout=timeout) as r: d = json.loads(r.read().decode("utf-8", "replace")) ms = int((time.time() - t0) * 1000) if (d.get("status") or "").lower() == "success": return {"ok": True, "country": (d.get("countryCode") or "").upper(), "countryName": d.get("country"), "ip": d.get("query"), "timezone": d.get("timezone"), "ms": ms} return {"ok": False, "error": d.get("message") or "no answer", "ms": ms} except urllib.error.HTTPError as e: return {"ok": False, "error": f"proxy rejected the login (HTTP {e.code})"} except Exception as e: return {"ok": False, "error": str(e) or e.__class__.__name__} # ──────────────────────────────────────────────────────────────────────────── # ৫) সুন্দর আউটপুট # ──────────────────────────────────────────────────────────────────────────── STATE_TXT = { "active": ("চালু", C.g), "used_up": ("MB শেষ", C.r), "expired": ("মেয়াদ শেষ", C.r), "disabled": ("বন্ধ", C.y), } def show(line, info, verify=False, as_json=False, api=API_DEFAULT): p = parse_line(line) or {"host": "?", "port": "?", "user": "?"} if not info.get("valid"): if as_json: print(json.dumps({"line": line, "valid": False, "error": info.get("error")})) else: print(C.r("✖ ") + C.bold("লাইন মেলেনি") + " — উজারনেম বা পাসওয়ার্ড ঠিক নয়") return 2 f = calc(info) state = info.get("state") or ("active" if f["leftBytes"] is None or f["leftBytes"] > 0 else "used_up") st_txt, st_col = STATE_TXT.get(state, (state, C.d)) if as_json: print(json.dumps({ "line": "%s:%s:%s:••••" % (p["host"], p["port"], info.get("username") or p["user"]), "type": info.get("type"), "country": info.get("country"), "state": state, "totalMB": f["limitMB"], "usedMB": f["usedMB"], "limitMB": f["limitMB"], "leftMB": f["leftMB"], "usedPercent": f["usedPercent"], "unlimited": f["unlimited"], "daysLeft": f["daysLeft"], "expiresAt": info.get("expiresAt"), "minutesLeft": info.get("minutesLeft"), }, ensure_ascii=False, indent=2)) else: cc = (info.get("country") or "-").upper() _u = line.split(":")[2] if line.count(":") >= 2 else "" # শুধু ইউজারনেমের শুরুটা দেখাই — পুরো সেশন/আইডি কোথাও ছাপি না who = (_u.split("_")[0][:10] if _u else "-") + "•••" print() print(C.bold(" NP Proxy — MB Check")) print(C.d(" " + "─" * 46)) print(f" লাইন : {C.b(who)} · দেশ {C.bold(cc)} · {info.get('type', 'line')}") print(f" অবস্থা : {st_col('● ' + st_txt)}" + (f" {C.d(str(info.get('minutesLeft')) + ' মিনিট বাকি')}" if info.get("minutesLeft") is not None else "")) print(C.d(" " + "─" * 46)) if f["unlimited"]: print(f" টোটাল MB : {C.bold('∞ আনলিমিটেড')}") else: print(f" টোটাল MB : {C.bold('%.2f' % f['limitMB'])} MB") print(f" ব্যবহার : {C.bold('%.2f' % f['usedMB'])} MB") if f["unlimited"]: print(f" বাকি : {C.g('∞')}") else: left_col = C.g if (f["leftMB"] or 0) > 0 else C.r print(f" বাকি : {left_col('%.2f' % f['leftMB'])} MB") print(f" গ্রাফ : {bar(f['usedPercent'])}") if f["daysLeft"] is not None: print(f" মেয়াদ : {info.get('expiresAt', '')[:10]} ({f['daysLeft']} দিন বাকি)") if verify: print(C.d(" " + "─" * 46)) print(" আসল exit যাচাই হচ্ছে…", end="", flush=True) v = verify_exit(line) print("\r" + " " * 30 + "\r", end="") if v.get("ok"): match = (v["country"] or "").upper() == cc mark = C.g("✔ মিলে গেছে") if match else C.r("✖ মেলেনি") print(f" exit IP : {C.bold(v['ip'])}") print(f" exit দেশ : {C.bold(v['country'])} {v.get('countryName') or ''} {mark} ({v['ms']} ms)") else: print(C.r(" exit যাচাই ব্যর্থ: ") + str(v.get("error"))) print() if state != "active" or (f["leftBytes"] is not None and f["leftBytes"] <= 0): return 1 return 0 # ──────────────────────────────────────────────────────────────────────────── # ৬) main # ──────────────────────────────────────────────────────────────────────────── def build_line(args): if args.line: return args.line if args.file: return None if args.user and args.passwd: host = args.host or "proxy.npproxy.shop" port = args.port or 8080 user = args.user cc = (args.country or "").upper() if cc and "-country-" not in user and "_country_" not in user: user = f"{user}-country-{cc}" return f"{host}:{port}:{user}:{args.passwd}" return None def main(argv=None): ap = argparse.ArgumentParser( prog="mb-check-bot", description="NP Proxy — MB Check Bot (used / left / state / expiry)", epilog="উদাহরণ: python3 mb-check-bot.py \"proxy.npproxy.shop:24442:HBr151py6_country-US_session-8f11f143_lifetime-30:PASS\" --verify-exit", formatter_class=argparse.RawDescriptionHelpFormatter, ) ap.add_argument("line", nargs="?", help="host:port:user:pass") ap.add_argument("--file", help="প্রতি লাইনে একটা করে লাইন আছে এমন ফাইল") ap.add_argument("--user"), ap.add_argument("--pass", dest="passwd") ap.add_argument("--host"), ap.add_argument("--port", type=int) ap.add_argument("--country", help="দেশের কোড (যেমন DE) — username-এ যোগ হবে") ap.add_argument("--api", default=API_DEFAULT, help="API ঠিকানা (ডিফল্ট %s)" % API_DEFAULT) ap.add_argument("--verify-exit", action="store_true", help="প্রক্সি দিয়ে আসল exit IP/দেশ যাচাই") ap.add_argument("--json", action="store_true", help="মেশিন-পাঠ্য JSON আউটপুট") ap.add_argument("--watch", type=int, metavar="SEC", help="প্রতি SEC সেকেন্ডে আবার চেক") ap.add_argument("--no-color", action="store_true") a = ap.parse_args(argv) if a.no_color: C.on = False lines = [] if a.file: try: with open(a.file, encoding="utf-8") as fh: lines = [x.strip() for x in fh if x.strip() and not x.startswith("#")] except OSError as e: print(C.r("ফাইল পড়া গেল না: ") + str(e)); return 2 else: one = build_line(a) if not one: ap.print_help(); return 2 lines = [one] rc = 0 while True: for ln in lines: p = parse_line(ln) if not p: print(C.r("ফরম্যাট ঠিক নয়: ") + ln + C.d(" (host:port:user:pass)")) rc = max(rc, 2); continue try: info = fetch_info(ln, api=a.api) except urllib.error.HTTPError as e: if e.code in (401, 403, 404): # লাইন/পাসওয়ার্ড মেলেনি info = {"valid": False, "error": "line not found (HTTP %s)" % e.code} else: body_txt = "" try: body_txt = e.read().decode("utf-8", "replace")[:200] except Exception: pass print(C.r("সার্ভার বলল: HTTP %s" % e.code) + (" " + body_txt if body_txt else "")) rc = max(rc, 2); continue except Exception as e: print(C.r("সংযোগ ব্যর্থ: ") + str(e)); rc = max(rc, 2); continue rc = max(rc, show(ln, info, verify=a.verify_exit, as_json=a.json, api=a.api)) if not a.watch: break if not a.json: print(C.d(" %d সেকেন্ড পর আবার… (Ctrl+C বন্ধ করুন)" % a.watch)) try: time.sleep(a.watch) except KeyboardInterrupt: print(); break return rc if __name__ == "__main__": try: sys.exit(main()) except KeyboardInterrupt: print("\nবন্ধ করা হলো") sys.exit(130)