Update app.py
Browse files
app.py
CHANGED
|
@@ -7,19 +7,20 @@ import psycopg2
|
|
| 7 |
from psycopg2 import pool
|
| 8 |
import time
|
| 9 |
from datetime import datetime
|
|
|
|
| 10 |
|
| 11 |
-
# --- Config (
|
| 12 |
MASSCAN_RATE = 100000 # Packets per second (go hard or go home)
|
| 13 |
TARGET_PORT = 11434 # Ollama default port
|
| 14 |
TARGET_RANGE = "0.0.0.0/0" # Scan the whole fucking internet
|
| 15 |
-
NUM_CHECKERS =
|
| 16 |
API_ENDPOINT = "/add-provider" # Internal endpoint to save IPs
|
| 17 |
PROCESSED_IPS_LIMIT = 15000000 # Clear memory occasionally (lol)
|
| 18 |
|
| 19 |
# --- DB Config (NeonDB, because why not?) ---
|
| 20 |
DB_URL = "postgresql://neondb_owner:npg_r7oFwW5XsmtG@ep-patient-lake-agwy3kca-pooler.c-2.eu-central-1.aws.neon.tech/ollama?sslmode=require&channel_binding=require"
|
| 21 |
|
| 22 |
-
# --- Global State (Fuck Thread Safety) ---
|
| 23 |
processed_ips = set()
|
| 24 |
ip_queue = queue.Queue()
|
| 25 |
active_checks = 0
|
|
@@ -102,7 +103,7 @@ def worker():
|
|
| 102 |
if not ip_queue.empty() and active_checks < NUM_CHECKERS:
|
| 103 |
ip = ip_queue.get()
|
| 104 |
active_checks += 1
|
| 105 |
-
|
| 106 |
time.sleep(0.1)
|
| 107 |
|
| 108 |
# --- Masscan Runner (Scan the whole internet, who cares?) ---
|
|
@@ -137,11 +138,14 @@ def run_masscan():
|
|
| 137 |
time.sleep(10)
|
| 138 |
|
| 139 |
# --- Start Workers (Let's go brrrr) ---
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
| 142 |
|
| 143 |
# --- Start Masscan (In a separate thread because why not?) ---
|
| 144 |
-
|
|
|
|
| 145 |
|
| 146 |
# --- Stats Reporter (Because you love watching chaos) ---
|
| 147 |
def report_stats():
|
|
@@ -153,7 +157,6 @@ def report_stats():
|
|
| 153 |
)
|
| 154 |
time.sleep(5)
|
| 155 |
|
| 156 |
-
threading.Thread(target=report_stats, daemon=True).start()
|
| 157 |
-
|
| 158 |
if __name__ == '__main__':
|
| 159 |
-
|
|
|
|
|
|
| 7 |
from psycopg2 import pool
|
| 8 |
import time
|
| 9 |
from datetime import datetime
|
| 10 |
+
import os
|
| 11 |
|
| 12 |
+
# --- Config (Still Fucking Reckless) ---
|
| 13 |
MASSCAN_RATE = 100000 # Packets per second (go hard or go home)
|
| 14 |
TARGET_PORT = 11434 # Ollama default port
|
| 15 |
TARGET_RANGE = "0.0.0.0/0" # Scan the whole fucking internet
|
| 16 |
+
NUM_CHECKERS = 50000 # Concurrent workers (more = better, who cares about rate limits?)
|
| 17 |
API_ENDPOINT = "/add-provider" # Internal endpoint to save IPs
|
| 18 |
PROCESSED_IPS_LIMIT = 15000000 # Clear memory occasionally (lol)
|
| 19 |
|
| 20 |
# --- DB Config (NeonDB, because why not?) ---
|
| 21 |
DB_URL = "postgresql://neondb_owner:npg_r7oFwW5XsmtG@ep-patient-lake-agwy3kca-pooler.c-2.eu-central-1.aws.neon.tech/ollama?sslmode=require&channel_binding=require"
|
| 22 |
|
| 23 |
+
# --- Global State (Still Fuck Thread Safety) ---
|
| 24 |
processed_ips = set()
|
| 25 |
ip_queue = queue.Queue()
|
| 26 |
active_checks = 0
|
|
|
|
| 103 |
if not ip_queue.empty() and active_checks < NUM_CHECKERS:
|
| 104 |
ip = ip_queue.get()
|
| 105 |
active_checks += 1
|
| 106 |
+
verify_and_send_ip(ip) # No threading here, Gunicorn already multithreads
|
| 107 |
time.sleep(0.1)
|
| 108 |
|
| 109 |
# --- Masscan Runner (Scan the whole internet, who cares?) ---
|
|
|
|
| 138 |
time.sleep(10)
|
| 139 |
|
| 140 |
# --- Start Workers (Let's go brrrr) ---
|
| 141 |
+
# ONLY START WORKERS IF NOT IN GUNICORN (Avoid double-threading)
|
| 142 |
+
if __name__ != '__main__' or os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
|
| 143 |
+
for _ in range(NUM_CHECKERS // 4): # Reduce workers since Gunicorn already multithreads
|
| 144 |
+
threading.Thread(target=worker, daemon=True).start()
|
| 145 |
|
| 146 |
# --- Start Masscan (In a separate thread because why not?) ---
|
| 147 |
+
if __name__ == '__main__':
|
| 148 |
+
threading.Thread(target=run_masscan, daemon=True).start()
|
| 149 |
|
| 150 |
# --- Stats Reporter (Because you love watching chaos) ---
|
| 151 |
def report_stats():
|
|
|
|
| 157 |
)
|
| 158 |
time.sleep(5)
|
| 159 |
|
|
|
|
|
|
|
| 160 |
if __name__ == '__main__':
|
| 161 |
+
threading.Thread(target=report_stats, daemon=True).start()
|
| 162 |
+
app.run(host='0.0.0.0', port=5000, threaded=True) # Let Flask handle threading
|