nmap.psm1
$Global:ToolsFolder = "$env:USERPROFILE\Tools" $Global:NmapFolder = Join-Path $Global:ToolsFolder 'nmap' $Global:NmapExe = Join-Path $Global:NmapFolder 'nmap.exe' function Get-NmapVersion { if (Test-Path $Global:NmapExe) { & $Global:NmapExe -V | Select-String -Pattern 'version [\d\.]+' | ForEach-Object { ($_ -split 'version ')[1].Trim() } } else { Write-Warning "Nmap not installed." } } function Install-Nmap { $url = "https://nmap.org/dist/nmap-7.94-setup.exe" $temp = "$env:TEMP\nmap-setup.exe" Write-Host "📥 Downloading Nmap installer..." Invoke-WebRequest -Uri $url -OutFile $temp Write-Host "🛠 Installing Nmap to $Global:NmapFolder..." Start-Process -FilePath $temp -ArgumentList "/S /D=$Global:NmapFolder" -Wait if (-not (Test-Path $Global:NmapExe)) { Write-Warning "❌ Nmap installation failed or path incorrect." } else { Write-Host "✅ Nmap installed successfully!" } } function Update-Nmap { Write-Host "🔍 Checking for Nmap updates..." $installed = Get-NmapVersion $latest = "7.94" # You can scrape the latest version from the site if needed if ($installed -ne $latest) { Write-Host "⬆️ Updating Nmap from version $installed to $latest..." Install-Nmap } else { Write-Host "🟢 Nmap is already up-to-date ($installed)" } } function Get-NmapPath { if (Test-Path $Global:NmapExe) { $Global:NmapExe } else { Write-Warning "Nmap not found." } } |