<# ========================================================= Windows Server 2025 – Optimized IP Scanner (PowerShell 7.4) Detect Used / Free IPs + Hostnames + MAC + RTT Author: ChatGPT ========================================================= #> param( [string]$Subnet = "192.168.1", [string]$OutputPath = "C:\IP_Scan_Report_2025.csv" ) Write-Host "`nStarting IP scan on subnet $Subnet.0/24 ..." -ForegroundColor Cyan $StartTime = Get-Date # Enable fast parallel processing in PowerShell 7.4 $IPs = 1..254 | ForEach-Object { "$Subnet.$_" } $Results = $IPs | ForEach-Object -Parallel { $ip = $_ $used = Test-Connection -Count 1 -Quiet -TimeoutSeconds 1 $ip if ($used) { # Try DNS name resolution try { $hostname = [System.Net.Dns]::GetHostEntry($ip).HostName } catch { $hostname = "Unknown" } # Grab MAC address from ARP table $arpEntry = arp -a $ip | Select-String $ip if ($arpEntry) { $mac = ($arpEntry.ToString().Split(" ", [System.StringSplitOptions]::RemoveEmptyEntries))[1] } else { $mac = "Unknown" } # Measure RTT (ping response time) try { $rtt = (Test-Connection -Count 1 $ip).ResponseTime } catch { $rtt = 0 } [PSCustomObject]@{ IPAddress = $ip Status = "Used" Hostname = $hostname MAC = $mac RTTms = $rtt ScanTime = (Get-Date) } } else { [PSCustomObject]@{ IPAddress = $ip Status = "Free" Hostname = "-" MAC = "-" RTTms = "-" ScanTime = (Get-Date) } } } -ThrottleLimit 50 # Tuned for Server 2025 multi-core performance # Output to screen in table format $Results | Sort-Object IPAddress | Format-Table # Export CSV $Results | Sort-Object IPAddress | Export-Csv -NoTypeInformation -Path $OutputPath # Export HTML as well $Results | ConvertTo-Html | Out-File ($OutputPath.Replace(".csv", ".html")) $EndTime = Get-Date $Duration = $EndTime - $StartTime Write-Host "`nScan complete!" -ForegroundColor Green Write-Host "Results saved to: $OutputPath" Write-Host "Total duration: $($Duration.TotalSeconds) seconds`n"