Skip to content

Instantly share code, notes, and snippets.

@awakecoding
Created April 1, 2023 20:44
Show Gist options
  • Save awakecoding/f364a56b4e90be1815f56e391ff79b20 to your computer and use it in GitHub Desktop.
Save awakecoding/f364a56b4e90be1815f56e391ff79b20 to your computer and use it in GitHub Desktop.
function Invoke-PortKnock
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,Position=0)]
[string] $HostName,
[Parameter(Mandatory=$true,Position=1)]
[Int32[]] $Sequence,
[Parameter(Mandatory=$false,Position=2)]
[Int32] $Delay = 500
)
$Sequence | ForEach-Object {
$KnockPort = $_
Write-Host "Knocking on $HostName TCP/$KnockPort"
$tcpClient = New-Object System.Net.Sockets.TcpClient
$tcpClient.BeginConnect($Hostname, $KnockPort, $null, $null) | Out-Null
$tcpClient.Close() | Out-Null
Start-Sleep -Milliseconds $Delay
}
}
# Invoke-PortKnock "192.168.25.110" @(10005, 10006, 10007)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment