Wasifali95 commited on
Commit
cb30d9c
·
verified ·
1 Parent(s): 29e234a

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +12 -0
  2. main.py +277 -0
  3. requirements.txt +0 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY main.py .
9
+
10
+ EXPOSE 7860
11
+
12
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # main.py
2
+ from fastapi import FastAPI, Query
3
+ from fastapi.responses import JSONResponse
4
+ from fastapi.middleware.cors import CORSMiddleware
5
+ import requests
6
+ import re
7
+ from bs4 import BeautifulSoup
8
+
9
+ app = FastAPI(title="SIM Tracker API", version="1.0.0", docs_url=None, redoc_url=None)
10
+
11
+ # CORS middleware
12
+ app.add_middleware(
13
+ CORSMiddleware,
14
+ allow_origins=["*"],
15
+ allow_credentials=True,
16
+ allow_methods=["*"],
17
+ allow_headers=["*"],
18
+ )
19
+
20
+ # Headers exactly as in your request
21
+ HEADERS = {
22
+ "Host": "simlivetracker.com.pk",
23
+ "sec-ch-ua-platform": "Android",
24
+ "user-agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Mobile Safari/537.36",
25
+ "sec-ch-ua": '"Not:A-Brand";v="99", "Google Chrome";v="145", "Chromium";v="145"',
26
+ "dnt": "1",
27
+ "sec-ch-ua-mobile": "?1",
28
+ "accept": "*/*",
29
+ "sec-fetch-site": "same-origin",
30
+ "sec-fetch-mode": "cors",
31
+ "sec-fetch-dest": "empty",
32
+ "referer": "https://simlivetracker.com.pk/",
33
+ "accept-encoding": "gzip, deflate, br, zstd",
34
+ "accept-language": "en-US,en;q=0.9,ur-PK;q=0.8,ur;q=0.7",
35
+ "priority": "u=1, i"
36
+ }
37
+
38
+ def detect_network(mobile: str) -> str:
39
+ """Detect network from mobile number prefix"""
40
+ if not mobile or len(mobile) < 4:
41
+ return "Unknown"
42
+
43
+ try:
44
+ prefix = int(mobile[:4])
45
+
46
+ if 301 <= prefix <= 329:
47
+ return "Jazz"
48
+ elif 310 <= prefix <= 319:
49
+ return "Zong"
50
+ elif 330 <= prefix <= 339:
51
+ return "Ufone"
52
+ elif 340 <= prefix <= 359:
53
+ return "Telenor"
54
+ else:
55
+ return "Unknown"
56
+ except:
57
+ return "Unknown"
58
+
59
+ def fetch_from_api(search: str, search_type: str) -> dict:
60
+ """Fetch data from simlivetracker.com.pk API"""
61
+ url = "https://simlivetracker.com.pk/api.php"
62
+ params = {
63
+ "search": search,
64
+ "type": search_type
65
+ }
66
+
67
+ try:
68
+ response = requests.get(url, params=params, headers=HEADERS, timeout=15)
69
+
70
+ if response.status_code == 200:
71
+ html_content = response.text
72
+ soup = BeautifulSoup(html_content, 'html.parser')
73
+
74
+ data = {
75
+ "success": True
76
+ }
77
+
78
+ # Extract data from HTML
79
+ text = html_content
80
+
81
+ # For mobile search - single record
82
+ if search_type == "mobile":
83
+ # Extract name
84
+ name_match = re.search(r'Name[:\s]*([^<\n]+)', text, re.IGNORECASE)
85
+ if name_match:
86
+ data["name"] = name_match.group(1).strip()
87
+
88
+ # Extract mobile
89
+ mobile_match = re.search(r'Mobile[:\s]*([0-9]+)', text, re.IGNORECASE)
90
+ if mobile_match:
91
+ data["mobile"] = mobile_match.group(1).strip()
92
+ # Detect network
93
+ data["network"] = detect_network(data["mobile"])
94
+
95
+ # Extract CNIC
96
+ cnic_match = re.search(r'CNIC[:\s]*([0-9-]+)', text, re.IGNORECASE)
97
+ if cnic_match:
98
+ data["cnic"] = cnic_match.group(1).strip()
99
+
100
+ # Extract address
101
+ address_match = re.search(r'Address[:\s]*([^<\n]+)', text, re.IGNORECASE)
102
+ if address_match:
103
+ data["address"] = address_match.group(1).strip()
104
+
105
+ # For CNIC search - multiple records
106
+ elif search_type == "cnic":
107
+ records = []
108
+
109
+ # Find all records in table format
110
+ rows = soup.find_all('tr')
111
+ for row in rows:
112
+ cols = row.find_all('td')
113
+ if len(cols) >= 3:
114
+ mobile = cols[0].get_text(strip=True) if len(cols) > 0 else ""
115
+ name = cols[1].get_text(strip=True) if len(cols) > 1 else ""
116
+ cnic_val = cols[2].get_text(strip=True) if len(cols) > 2 else ""
117
+ address_val = cols[3].get_text(strip=True) if len(cols) > 3 else ""
118
+
119
+ if mobile and re.match(r'^03[0-9]{9}$', mobile):
120
+ records.append({
121
+ "name": name,
122
+ "mobile": mobile,
123
+ "cnic": cnic_val,
124
+ "network": detect_network(mobile),
125
+ "address": address_val
126
+ })
127
+
128
+ # Alternative: regex for multiple records
129
+ if not records:
130
+ pattern = r'([0-9]{11}).*?([A-Za-z\s]+).*?([0-9-]{15})'
131
+ matches = re.findall(pattern, text, re.DOTALL)
132
+ for match in matches:
133
+ mobile = match[0].strip()
134
+ name = match[1].strip()
135
+ cnic_val = match[2].strip()
136
+ if mobile and re.match(r'^03[0-9]{9}$', mobile):
137
+ records.append({
138
+ "name": name,
139
+ "mobile": mobile,
140
+ "cnic": cnic_val,
141
+ "network": detect_network(mobile)
142
+ })
143
+
144
+ if records:
145
+ data["cnic"] = search
146
+ data["name"] = records[0].get("name") if records else ""
147
+ data["total_sims"] = len(records)
148
+ data["records"] = records
149
+ else:
150
+ # Single record fallback
151
+ name_match = re.search(r'Name[:\s]*([^<\n]+)', text, re.IGNORECASE)
152
+ mobile_match = re.search(r'Mobile[:\s]*([0-9]+)', text, re.IGNORECASE)
153
+ cnic_match = re.search(r'CNIC[:\s]*([0-9-]+)', text, re.IGNORECASE)
154
+ address_match = re.search(r'Address[:\s]*([^<\n]+)', text, re.IGNORECASE)
155
+
156
+ if mobile_match:
157
+ single_record = {
158
+ "name": name_match.group(1).strip() if name_match else "",
159
+ "mobile": mobile_match.group(1).strip(),
160
+ "cnic": cnic_match.group(1).strip() if cnic_match else "",
161
+ "network": detect_network(mobile_match.group(1).strip()),
162
+ "address": address_match.group(1).strip() if address_match else ""
163
+ }
164
+ data["cnic"] = search
165
+ data["name"] = single_record["name"]
166
+ data["total_sims"] = 1
167
+ data["records"] = [single_record]
168
+
169
+ return data
170
+
171
+ else:
172
+ return {
173
+ "success": False,
174
+ "message": f"API returned status {response.status_code}"
175
+ }
176
+
177
+ except Exception as e:
178
+ return {
179
+ "success": False,
180
+ "message": str(e)
181
+ }
182
+
183
+ @app.get("/")
184
+ async def root():
185
+ return JSONResponse(
186
+ status_code=200,
187
+ content={
188
+ "status": "active",
189
+ "service": "SIM Database Tracker",
190
+ "endpoints": {
191
+ "mobile": "/api?search=03007058868",
192
+ "cnic": "/api?search=35201-1234567-8"
193
+ },
194
+ "developer": "WASIF ALI",
195
+ "telegram": "@THE_FREE_HACKS"
196
+ }
197
+ )
198
+
199
+ @app.get("/api")
200
+ async def search(search: str = Query(..., description="Mobile number or CNIC")):
201
+ """Search by mobile number or CNIC"""
202
+
203
+ search_clean = re.sub(r'\s+', '', search)
204
+
205
+ # Detect type
206
+ if re.match(r'^03[0-9]{9}$', search_clean):
207
+ search_type = "mobile"
208
+ elif re.match(r'^[0-9]{5}-[0-9]{7}-[0-9]$', search_clean) or re.match(r'^[0-9]{13}$', search_clean):
209
+ search_type = "cnic"
210
+ # Format CNIC
211
+ if re.match(r'^[0-9]{13}$', search_clean):
212
+ search_clean = f"{search_clean[:5]}-{search_clean[5:12]}-{search_clean[12]}"
213
+ else:
214
+ return JSONResponse(
215
+ status_code=400,
216
+ content={
217
+ "status": False,
218
+ "message": "Invalid input. Use mobile (03xxxxxxxxx) or CNIC (xxxxx-xxxxxxx-x)",
219
+ "developer": "WASIF ALI",
220
+ "telegram": "@THE_FREE_HACKS"
221
+ }
222
+ )
223
+
224
+ # Fetch from your API
225
+ result = fetch_from_api(search_clean, search_type)
226
+
227
+ if result.get("success"):
228
+ response_data = {
229
+ "status": True,
230
+ "developer": "WASIF ALI",
231
+ "telegram": "@THE_FREE_HACKS"
232
+ }
233
+
234
+ if search_type == "mobile":
235
+ if result.get("name"):
236
+ response_data["name"] = result["name"]
237
+ if result.get("mobile"):
238
+ response_data["mobile"] = result["mobile"]
239
+ if result.get("cnic"):
240
+ response_data["cnic"] = result["cnic"]
241
+ if result.get("network"):
242
+ response_data["network"] = result["network"]
243
+ if result.get("address"):
244
+ response_data["address"] = result["address"]
245
+ else:
246
+ if result.get("cnic"):
247
+ response_data["cnic"] = result["cnic"]
248
+ if result.get("name"):
249
+ response_data["name"] = result["name"]
250
+ if result.get("total_sims"):
251
+ response_data["total_sims"] = result["total_sims"]
252
+ if result.get("records"):
253
+ response_data["records"] = result["records"]
254
+
255
+ return JSONResponse(status_code=200, content=response_data)
256
+ else:
257
+ return JSONResponse(
258
+ status_code=404,
259
+ content={
260
+ "status": False,
261
+ "message": result.get("message", "No data found"),
262
+ "developer": "WASIF ALI",
263
+ "telegram": "@THE_FREE_HACKS"
264
+ }
265
+ )
266
+
267
+ @app.get("/test")
268
+ async def test():
269
+ return JSONResponse(
270
+ status_code=200,
271
+ content={
272
+ "status": True,
273
+ "message": "API is working",
274
+ "developer": "WASIF ALI",
275
+ "telegram": "@THE_FREE_HACKS"
276
+ }
277
+ )
requirements.txt ADDED
File without changes