Created
May 17, 2017 23:10
-
-
Save peaeater/0a0696348fce9f49c606f946fc2cde33 to your computer and use it in GitHub Desktop.
Scans to see if an IP is listening on a given port.
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
param ( | |
[int]$port, | |
[string]$ip | |
) | |
if (Test-Connection -BufferSize 32 -Count 1 -Quiet -ComputerName $ip) { | |
$socket = new-object System.Net.Sockets.TcpClient($ip, $port) | |
if ($socket.Connected) { | |
write-host "$ip is listening on port $port" | |
$socket.Close() | |
} | |
else { | |
write-host "$ip NOT listening on port $port" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment