107 lines
3.3 KiB
PowerShell
107 lines
3.3 KiB
PowerShell
# 超快速 AMT 端口扫描(使用异步 TCP 连接)
|
|
# 强制设置编码
|
|
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
|
|
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding(936) # GBK for Chinese Windows
|
|
|
|
$subnet = "192.168.8"
|
|
$ports = @(16992, 16993, 623) # AMT HTTP, HTTPS, RMCP
|
|
$timeout = 100 # 毫秒
|
|
|
|
Write-Host "开始快速扫描 $subnet.0/24 网段的 AMT 端口..." -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
$results = @()
|
|
$tasks = @()
|
|
|
|
# 创建所有扫描任务
|
|
for ($i = 1; $i -le 254; $i++) {
|
|
$ip = "$subnet.$i"
|
|
|
|
foreach ($port in $ports) {
|
|
$task = [PSCustomObject]@{
|
|
IP = $ip
|
|
Port = $port
|
|
Client = New-Object System.Net.Sockets.TcpClient
|
|
AsyncResult = $null
|
|
}
|
|
|
|
try {
|
|
$task.AsyncResult = $task.Client.BeginConnect($ip, $port, $null, $null)
|
|
$tasks += $task
|
|
} catch {
|
|
$task.Client.Dispose()
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Host "等待扫描完成..." -ForegroundColor Yellow
|
|
|
|
# 等待所有任务完成
|
|
Start-Sleep -Milliseconds ($timeout + 100)
|
|
|
|
# 检查结果
|
|
$foundDevices = @{}
|
|
|
|
foreach ($task in $tasks) {
|
|
try {
|
|
if ($task.AsyncResult.IsCompleted) {
|
|
$task.Client.EndConnect($task.AsyncResult)
|
|
|
|
if ($task.Client.Connected) {
|
|
if (-not $foundDevices.ContainsKey($task.IP)) {
|
|
$foundDevices[$task.IP] = @()
|
|
}
|
|
$foundDevices[$task.IP] += $task.Port
|
|
}
|
|
}
|
|
} catch {
|
|
# 连接失败
|
|
} finally {
|
|
$task.Client.Close()
|
|
$task.Client.Dispose()
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "扫描完成!发现 $($foundDevices.Count) 个 AMT 设备" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
if ($foundDevices.Count -gt 0) {
|
|
foreach ($ip in $foundDevices.Keys | Sort-Object) {
|
|
$openPorts = $foundDevices[$ip] -join ", "
|
|
Write-Host "[✓] $ip - 开放端口: $openPorts" -ForegroundColor Green
|
|
|
|
$results += [PSCustomObject]@{
|
|
IP = $ip
|
|
OpenPorts = $openPorts
|
|
HTTP = if ($foundDevices[$ip] -contains 16992) { "http://${ip}:16992" } else { "" }
|
|
HTTPS = if ($foundDevices[$ip] -contains 16993) { "https://${ip}:16993" } else { "" }
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|
|
$results | Format-Table IP, OpenPorts, HTTPS -AutoSize
|
|
|
|
# 保存结果
|
|
$results | Export-Csv -Path "amt-devices-fast.csv" -NoTypeInformation -Encoding UTF8
|
|
Write-Host "结果已保存到: amt-devices-fast.csv" -ForegroundColor Green
|
|
|
|
Write-Host ""
|
|
Write-Host "可以通过以下地址访问 AMT Web 界面:" -ForegroundColor Cyan
|
|
foreach ($result in $results) {
|
|
if ($result.HTTPS) {
|
|
Write-Host " $($result.HTTPS)" -ForegroundColor Yellow
|
|
} elseif ($result.HTTP) {
|
|
Write-Host " $($result.HTTP)" -ForegroundColor Yellow
|
|
}
|
|
}
|
|
} else {
|
|
Write-Host "未发现任何 AMT 设备" -ForegroundColor Yellow
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "提示: 如需详细信息,对发现的 IP 运行:" -ForegroundColor Gray
|
|
Write-Host " .\RMCPPing.exe -host <IP>" -ForegroundColor Gray
|