Created
February 19, 2025 21:13
-
-
Save joshfinley/37467a1dd6fc388e1cc7be02e29bf197 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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