Skip to content

Instantly share code, notes, and snippets.

@peaeater
Created May 17, 2017 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peaeater/0a0696348fce9f49c606f946fc2cde33 to your computer and use it in GitHub Desktop.
Save peaeater/0a0696348fce9f49c606f946fc2cde33 to your computer and use it in GitHub Desktop.
Scans to see if an IP is listening on a given port.
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