PoshCode Archive  Artifact [65405a186a]

Artifact 65405a186a315678ada39967b6eb1851fae12be78f54bd45f9d09b9b8a57a813:

  • File Test-Port.ps1 — part of check-in [7bc7b3b706] at 2018-06-10 13:09:31 on branch trunk — Test-Port creates a TCP connection to specified port. (user: BSonPosh size: 657)

# encoding: ascii
# api: powershell
# title: Test-Port.ps1
# description: Test-Port creates a TCP connection to specified port.
# version: 0.1
# author: BSonPosh
# license: CC0
# x-poshcode-id: 2392
# x-derived-from-id: 6442
# x-archived: 2016-08-19T05:15:23
# x-published: 2011-11-28T08:57:00
#
#
param ($ComputerName,$Port)

$sock = new-object System.Net.Sockets.Socket -ArgumentList $([System.Net.Sockets.AddressFamily]::InterNetwork),$([System.Net.Sockets.SocketType]::Stream),$([System.Net.Sockets.ProtocolType]::Tcp)

try {
    $sock.Connect($ComputerName,$Port)
    $sock.Connected
    $sock.Close()

}
catch {
    $false
}