Tuesday, November 11, 2014

#32 : How to check if TCP/IP Port is open?

Without talking much, please find the code below.
#------------------------------------------------------------------------------------------
#     Script : Check_Port.ps1 
#     Author : Som DT.
#    Purpose : Checking if Port is open on target TCP/IP server from current host 
#------------------------------------------------------------------------------------------

function Check-Port([string]$HostName, [string] $PortNumber) 
{
    #--Set the client --# 
    $tcp = New-Object System.Net.Sockets.TcpClient
    
    #--Connecting to the Port --# 
    $tcp.connect($HostName , $PortNumber ) 
    

}

Enjoy!

No comments:

Post a Comment

#112: How to handle xml document in Powershell?

 In PowerShell, you can handle XML data using various cmdlets and methods provided by the .NET Framework. Here's a basic guide on how to...