Created
April 1, 2023 20:44
-
-
Save awakecoding/f364a56b4e90be1815f56e391ff79b20 to your computer and use it in GitHub Desktop.
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
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