-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleanup-ports.ps1
More file actions
77 lines (65 loc) · 3.28 KB
/
cleanup-ports.ps1
File metadata and controls
77 lines (65 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# SQLMap GUI - Port Cleanup Script
# Run this script as Administrator if you encounter port blocking issues
# This will kill all SQLMap processes and free up blocked ports
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "SQLMap GUI - Port Cleanup Tool" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Check if running as administrator
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "⚠️ WARNING: Not running as Administrator" -ForegroundColor Yellow
Write-Host " Some cleanup operations may fail without admin privileges" -ForegroundColor Yellow
Write-Host " Right-click and select 'Run as Administrator' for best results" -ForegroundColor Yellow
Write-Host ""
}
# Step 1: Kill all Python processes running sqlmapapi.py
Write-Host "Step 1: Checking for SQLMap API processes..." -ForegroundColor White
$sqlmapProcesses = Get-Process python* -ErrorAction SilentlyContinue | Where-Object { $_.CommandLine -like '*sqlmapapi.py*' }
if ($sqlmapProcesses) {
Write-Host " Found $($sqlmapProcesses.Count) SQLMap process(es)" -ForegroundColor Yellow
foreach ($proc in $sqlmapProcesses) {
Write-Host " Killing PID $($proc.Id) - $($proc.ProcessName)" -ForegroundColor Yellow
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue
}
Write-Host " ✅ SQLMap processes cleaned" -ForegroundColor Green
} else {
Write-Host " ✅ No SQLMap processes found" -ForegroundColor Green
}
Write-Host ""
# Step 2: Clean up ports
Write-Host "Step 2: Cleaning up ports..." -ForegroundColor White
$portsToClean = @(3000, 9090, 9091, 9092, 9093, 9094)
$cleanedCount = 0
foreach ($port in $portsToClean) {
$connection = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue | Select-Object -First 1
if ($connection) {
$process = Get-Process -Id $connection.OwningProcess -ErrorAction SilentlyContinue
Write-Host " Port $port - PID $($connection.OwningProcess) ($($process.ProcessName))" -ForegroundColor Yellow
try {
Stop-Process -Id $connection.OwningProcess -Force -ErrorAction Stop
Write-Host " ✅ Killed process on port $port" -ForegroundColor Green
$cleanedCount++
} catch {
Write-Host " ❌ Failed to kill process on port $port (may need admin)" -ForegroundColor Red
}
} else {
Write-Host " Port $port - Available" -ForegroundColor Gray
}
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
if ($cleanedCount -gt 0) {
Write-Host "✅ Cleanup complete! Freed $cleanedCount port(s)" -ForegroundColor Green
} else {
Write-Host "✅ All ports are clear!" -ForegroundColor Green
}
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "You can now restart your backend server." -ForegroundColor White
Write-Host ""
# Optional: Pause to see results
if ($Host.Name -eq "ConsoleHost") {
Write-Host "Press any key to exit..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}