30 lines
1.0 KiB
PostScript
30 lines
1.0 KiB
PostScript
# Lokales Subnetz automatisch ermitteln
|
|
$localIP = (Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias Ethernet* | Where-Object {$_.PrefixLength -le 32}).IPAddress
|
|
if (-not $localIP) { $localIP = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.PrefixLength -le 32}).IPAddress }
|
|
$subnet = ($localIP -split '\.')[0..2] -join '.'
|
|
|
|
Write-Host "Scanning subnet $subnet.0/24 ..." -ForegroundColor Cyan
|
|
|
|
$results = @()
|
|
|
|
1..254 | ForEach-Object {
|
|
$ip = "$subnet.$_"
|
|
if (Test-Connection -ComputerName $ip -Count 1 -Quiet) {
|
|
# MAC-Adresse über ARP abfragen
|
|
$mac = (arp -a $ip | Select-String $ip) -replace '\s{2,}', ' ' | ForEach-Object { ($_ -split ' ')[1] }
|
|
# Hostname auflösen
|
|
try {
|
|
$hostname = ([System.Net.Dns]::GetHostEntry($ip)).HostName
|
|
} catch {
|
|
$hostname = "unbekannt"
|
|
}
|
|
$results += [PSCustomObject]@{
|
|
IP = $ip
|
|
MAC = $mac
|
|
Hostname = $hostname
|
|
}
|
|
}
|
|
}
|
|
|
|
# Ergebnisse ausgeben
|
|
$results | Format-Table -AutoSize |