I do not have telnet
command in my system.
However my system is installed with Windows 10
, so there must be a way to check whether particular port is open or not in a remote system. That particular remote system is accessible I had checked with ping
command.
So here is my simple question,- how to check whether particular port is open or not using powershell
.
Command netstat
could brief for local system service & port and particular protocol either UDP or TCP is up & runnning. As I do not have telnet
I need this to be sorted out and tackled by powershell
. Any advise and suggestion are welcome.
Test-NetConnection ###.###.###.### -Port ##
You can use the following to try and open a port, if no error is returned the port is open:
$ipaddress = ""
$port = ""
$tcpClient = new-object Net.Sockets.TcpClient
$tcpClient.Connect("$ipaddress", $Port)
$tcpClient.Dispose()
Here's a more complete example, which returns true/false which is the way that Test-Path works:
function Test-Port
{
param
(
$Address,
$Port
)
$tcpClient = new-object Net.Sockets.TcpClient
try
{
$tcpClient.Connect("$Address", $Port)
$true
}
catch
{
$false
}
finally
{
$tcpClient.Dispose()
}
}
Test-Port -Address localhost -Port 80
Test-Port -Address localhost -Port 81
Depending on the version of Powershell/Windows you are using Test-NetConnection may be more appropriate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With