<# Mini network scanner with menu: 1) Light scan: ping (ICMP) + net view 2) SMB scan: TCP port 445 + net view - Asks for network prefix (example: 10.0.0) - Asks for host range (start / end) - Asks for CSV output path - Shows a progress bar in the console - Exports results to CSV ASCII only, no accents, no unicode. #> function Update-ProgressBar { param( [int]$Current, [int]$Total, [string]$Label ) if ($Total -le 0) { return } $percent = [math]::Floor(($Current / $Total) * 100) $barLength = 30 $filled = [math]::Floor($percent * $barLength / 100) $empty = $barLength - $filled $bar = "[" + ("#" * $filled) + ("-" * $empty) + "]" Write-Host ("`r" + $bar + " " + $percent + "% (" + $Current + " / " + $Total + ") " + $Label) -NoNewline } Write-Host "=============================" Write-Host " Mini network scanner" Write-Host "=============================" Write-Host "" $netInput = Read-Host "Enter network prefix (example: 10.0.0)" if (-not $netInput) { Write-Host "No input, using default 10.0.0" -ForegroundColor Yellow $netInput = "10.0.0" } if ($netInput.EndsWith(".")) { $NetworkPrefix = $netInput } else { $NetworkPrefix = $netInput + "." } $startInput = Read-Host "Enter start host (default 1)" if (-not $startInput) { $startInput = "1" } $endInput = Read-Host "Enter end host (default 254)" if (-not $endInput) { $endInput = "254" } [int]$StartHost = $startInput [int]$EndHost = $endInput $csvPathInput = Read-Host "Enter CSV output path (default .\net_scan_results.csv)" if (-not $csvPathInput) { $CsvPath = ".\net_scan_results.csv" } else { $CsvPath = $csvPathInput } Write-Host "" Write-Host "Scan options:" -ForegroundColor Cyan Write-Host "1 - Light scan (ping + net view)" Write-Host "2 - SMB scan (port 445 + net view)" Write-Host "" $choice = Read-Host "Choose option (1 or 2)" $results = @() if ($choice -eq "1") { Write-Host "`n[INFO] Running LIGHT scan (ping + net view)" -ForegroundColor Cyan Write-Host ("Network: " + $NetworkPrefix + $StartHost + "-" + $EndHost) -ForegroundColor Cyan Write-Host ("CSV output: " + $CsvPath) -ForegroundColor Cyan $total = $EndHost - $StartHost + 1 $current = 0 for ($i = $StartHost; $i -le $EndHost; $i++) { $current++ $ip = "$NetworkPrefix$i" Update-ProgressBar -Current $current -Total $total -Label ("Testing " + $ip) $isUp = Test-Connection -ComputerName $ip -Count 1 -Quiet -ErrorAction SilentlyContinue if ($isUp) { Write-Host "" # end progress bar line Write-Host ("[" + $ip + "] is up") -ForegroundColor Yellow $netViewOutput = net view "\\$ip" 2>$null if ($netViewOutput) { $netViewOutput | ForEach-Object { Write-Host " $_" } } else { Write-Host " net view returned no data or access denied." -ForegroundColor DarkGray } $results += [PSCustomObject]@{ Mode = "Light" IP = $ip SMBPort445 = "Unknown (ping only)" NetViewRaw = ($netViewOutput -join " || ") } } } Write-Host "" # break progress bar line } elseif ($choice -eq "2") { Write-Host "`n[INFO] Running SMB scan (TCP 445 + net view)" -ForegroundColor Cyan Write-Host ("Network: " + $NetworkPrefix + $StartHost + "-" + $EndHost) -ForegroundColor Cyan Write-Host ("CSV output: " + $CsvPath) -ForegroundColor Cyan if (-not (Get-Command Test-NetConnection -ErrorAction SilentlyContinue)) { Write-Host "[WARN] Test-NetConnection is not available on this PowerShell version." -ForegroundColor Red Write-Host " Option 2 cannot run. Please use option 1 or a newer PowerShell." exit } $total = $EndHost - $StartHost + 1 $current = 0 for ($i = $StartHost; $i -le $EndHost; $i++) { $current++ $ip = "$NetworkPrefix$i" Update-ProgressBar -Current $current -Total $total -Label ("Testing SMB " + $ip) $smbOpen = Test-NetConnection -ComputerName $ip -Port 445 -InformationLevel Quiet -WarningAction SilentlyContinue if ($smbOpen) { Write-Host "" # end progress bar line Write-Host ("[" + $ip + "] - SMB port 445 open") -ForegroundColor Yellow $netViewOutput = net view "\\$ip" 2>$null if ($netViewOutput) { $netViewOutput | ForEach-Object { Write-Host " $_" } } else { Write-Host " net view returned no data or access denied." -ForegroundColor DarkGray } $results += [PSCustomObject]@{ Mode = "SMB" IP = $ip SMBPort445 = "Open" NetViewRaw = ($netViewOutput -join " || ") } } } Write-Host "" # break progress bar line } else { Write-Host "`n[ERROR] Invalid choice. Please run the script again and choose 1 or 2." -ForegroundColor Red exit } if ($results.Count -gt 0) { $results | Export-Csv -NoTypeInformation -Encoding UTF8 -Path $CsvPath Write-Host ("`n[OK] Scan done. Results saved to " + $CsvPath) -ForegroundColor Green } else { Write-Host "`n[OK] Scan done. No host found with the selected method." -ForegroundColor Green }