-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknock.ps1
49 lines (38 loc) · 1.12 KB
/
knock.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<#
.SYNOPSIS
Given a host, looks up its port sequence and knocks on it.
.DESCRIPTION
Given a host, looks up its port sequence and knocks on it.
Version: v2.2.1
Homepage: https://github.com/jahed/knock
Donate: https://jahed.dev/donate
.PARAMETER TargetHost
Target host. Where you want to knock. Must exist in config file.
.PARAMETER ConfigFile
Config file location. Defaults to ~/.config/knock/hosts.json.
.INPUTS
None.
.OUTPUTS
None.
.EXAMPLE
PS> .\knock.ps1 -ConfigFile .\knock.json example.com
Will knock on example.com at ports 1000 then 2000 then 3000 given the config file:
{
"example.com": ["1000", "2000", "3000"]
}
.LINK
https://github.com/jahed/knock
#>
param(
[Parameter(Mandatory=$true,Position=0)]
[String] $TargetHost
,
[Parameter()]
[ValidateScript({ Test-Path -PathType Leaf $_ })]
[String] $ConfigFile="~\.config\knock\hosts.json"
)
Get-Content -Raw ~\.config\knock\hosts.json | ConvertFrom-Json | % { $_.$TargetHost} | ForEach-Object -Process {
Start-Job -ScriptBlock {
Test-NetConnection -ComputerName $TargetHost -Port $_ -InformationLevel Quiet
} | Wait-Job -Timeout 1 | Out-Null
}