WebSocket connection load test
(self, target_ip, target_port, duration)
| 359 | time.sleep(1.0 / self.rate_limit) |
| 360 | |
| 361 | def websocket_load_test(self, target_ip, target_port, duration): |
| 362 | """WebSocket connection load test""" |
| 363 | end_time = time.time() + duration |
| 364 | |
| 365 | # Check if websocket-client is available |
| 366 | try: |
| 367 | import websocket |
| 368 | except ImportError: |
| 369 | print(f"{Colors.RED}[!] websocket-client not available. Installing...{Colors.RESET}") |
| 370 | dependency_manager = DependencyManager() |
| 371 | if not dependency_manager.install_package('websocket-client'): |
| 372 | print(f"{Colors.RED}[!] Failed to install websocket-client{Colors.RESET}") |
| 373 | return |
| 374 | import websocket |
| 375 | |
| 376 | scheme = "wss" if target_port == 443 else "ws" |
| 377 | ws_url = f"{scheme}://{target_ip}:{target_port}/ws" |
| 378 | |
| 379 | while time.time() < end_time and self.running: |
| 380 | try: |
| 381 | ws = websocket.create_connection(ws_url, timeout=self.timeout) |
| 382 | |
| 383 | # Send test messages |
| 384 | for i in range(10): |
| 385 | if time.time() > end_time: |
| 386 | break |
| 387 | message = json.dumps({"type": "ping", "data": f"test_{i}"}) |
| 388 | ws.send(message) |
| 389 | self.stats['requests_sent'] += 1 |
| 390 | self.stats['requests_successful'] += 1 |
| 391 | time.sleep(0.1) |
| 392 | |
| 393 | ws.close() |
| 394 | |
| 395 | except Exception as e: |
| 396 | self.stats['requests_failed'] += 1 |
| 397 | self.stats['requests_sent'] += 1 |
| 398 | |
| 399 | def database_query_simulation(self, target_ip, target_port, duration): |
| 400 | """Simulate database-intensive operations""" |
nothing calls this directly
no test coverage detected