Skip to content

Instantly share code, notes, and snippets.

@joshfinley
Created February 19, 2025 21:13
Show Gist options
  • Save joshfinley/37467a1dd6fc388e1cc7be02e29bf197 to your computer and use it in GitHub Desktop.
Save joshfinley/37467a1dd6fc388e1cc7be02e29bf197 to your computer and use it in GitHub Desktop.
# Run arp -a and extract IP addresses
$ips = arp -a | ForEach-Object {
if ($_ -match '(\d+\.\d+\.\d+\.\d+)') {
$matches[1]
}
} | Where-Object { $_ -ne "0.0.0.0" -and $_ -ne "255.255.255.255" }
# Function to check SMB connectivity
function Check-SMB {
param (
[string]$ip
)
$tcp = New-Object System.Net.Sockets.TcpClient
if ($tcp.ConnectAsync($ip, 445).Wait(100)) {
Write-Output "SMB is OPEN on $ip"
} else {
Write-Output "SMB is CLOSED on $ip"
}
$tcp.Close()
}
# Check SMB on each discovered IP
foreach ($ip in $ips) {
Check-SMB -ip $ip
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment