Created
October 14, 2015 08:42
-
-
Save jzi96/c5c5fdf14143dfe7c48e to your computer and use it in GitHub Desktop.
Small Powershell script to check a specific port on host, if that can be accessed. (Old telnet style port check) This can be useful, if you are behind a firewall.
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
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$True,Position=1)] | |
[string]$hostname, | |
[Parameter(Mandatory=$True,Position=2)] | |
[int]$port | |
) | |
try { | |
$tcp=new-object System.Net.Sockets.TcpClient | |
$tcp.ReceiveTimeout=20 | |
$tcp.SendTimeout=20 | |
$tcp.connect($hostname,$port) | |
$tcp.close() | |
Write-Host "Connect to "$hostname":"$port "successfull" | |
} | |
catch { | |
"Exception occured" | |
Write-Host "Failed to connect to" $hostname":"$port | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment