Skip to content

Instantly share code, notes, and snippets.

@jzi96
Created October 14, 2015 08:42
Show Gist options
  • Save jzi96/c5c5fdf14143dfe7c48e to your computer and use it in GitHub Desktop.
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.
[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