$subnet = "192.168.
1"
$start = 1
$end = 254
$portsToCheck = @(80, 443, 3389)
$results = @()
$jobs = @()
Write-Host "Iniciando varredura na rede $subnet.0/24 estilo IPScan..." -
ForegroundColor Cyan
for ($i = $start; $i -le $end; $i++) {
$ip = "$subnet.$i"
$jobs += Start-Job -ScriptBlock {
param($ip, $portsToCheck)
$isActive = $false
$hostName = "N/D"
$mac = "N/D"
# 1 - Tenta ping
if (Test-Connection -ComputerName $ip -Count 1 -Quiet -ErrorAction
SilentlyContinue) {
$isActive = $true
} else {
# 2 - Se não pingar, tenta conexão em portas comuns
foreach ($port in $portsToCheck) {
try {
$tcpClient = New-Object [Link]
$iar = $[Link]($ip, $port, $null, $null)
$success = $[Link](300)
if ($success -and $[Link]) {
$[Link]($iar)
$[Link]()
$isActive = $true
break
}
} catch { }
}
}
if ($isActive) {
# Nome do host
try {
$hostName = ([[Link]]::GetHostEntry($ip)).HostName
} catch { }
# MAC Address via ARP
arp -a | ForEach-Object {
if ($_ -match $ip) {
$macMatch = ($_ -split '\s+') | Where-Object { $_ -match '([0-
9A-Fa-f]{2}-){5}[0-9A-Fa-f]{2}' }
if ($macMatch) { $mac = $macMatch[0] }
}
}
return [PSCustomObject]@{
IP = $ip
Hostname = $hostName
MAC = $mac
}
}
} -ArgumentList $ip, $portsToCheck
}
foreach ($job in $jobs) {
$job | Wait-Job
$result = Receive-Job -Job $job
if ($result) {
$results += $result
}
Remove-Job -Job $job
}
Write-Host "`nDispositivos ativos estilo IPScan encontrados:" -ForegroundColor
Green
$results | Sort-Object IP | Format-Table -AutoSize