0% found this document useful (0 votes)
15 views2 pages

Script de Rede

The document is a PowerShell script designed to scan a local network for active devices within a specified subnet. It attempts to ping each IP address and checks common ports (80, 443, 3389) for connectivity, collecting information such as hostname and MAC address. The results are displayed in a formatted table after the scan is complete.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Script de Rede

The document is a PowerShell script designed to scan a local network for active devices within a specified subnet. It attempts to ping each IP address and checks common ports (80, 443, 3389) for connectivity, collecting information such as hostname and MAC address. The results are displayed in a formatted table after the scan is complete.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

$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

You might also like