mirror of
https://github.com/house-of-vanity/OutFleet.git
synced 2025-08-21 14:37:16 +00:00
Update windows_task.ps1
This commit is contained in:
committed by
GitHub
parent
dceb07137a
commit
f7ce671427
@@ -1,5 +1,5 @@
|
|||||||
if ($args.Count -lt 2) {
|
if ($args.Count -lt 3) {
|
||||||
Write-Host "Usage: windows_task.ps1 <url> <sslocal_path> <comment>"
|
Write-Host "Usage: windows_task.ps1 <url> <sslocal_path> <local_port>"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,6 +11,24 @@ $localAddr = "localhost"
|
|||||||
$checkInterval = 60
|
$checkInterval = 60
|
||||||
$previousPassword = ""
|
$previousPassword = ""
|
||||||
|
|
||||||
|
# Function to get the process ID of the process listening on a specific port
|
||||||
|
function Get-ProcessByPort {
|
||||||
|
param (
|
||||||
|
[int]$port
|
||||||
|
)
|
||||||
|
|
||||||
|
# Use Get-NetTCPConnection to find the process listening on the given port
|
||||||
|
$connection = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue | Where-Object { $_.State -eq 'Listen' }
|
||||||
|
|
||||||
|
if ($connection) {
|
||||||
|
# Get the owning process ID (OwningProcess) from the connection
|
||||||
|
$pid = $connection.OwningProcess
|
||||||
|
return Get-Process -Id $pid -ErrorAction SilentlyContinue
|
||||||
|
} else {
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Function to start sslocal
|
# Function to start sslocal
|
||||||
function Start-SSLocal {
|
function Start-SSLocal {
|
||||||
param (
|
param (
|
||||||
@@ -25,8 +43,12 @@ function Start-SSLocal {
|
|||||||
$encodedCredentials = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($credentials))
|
$encodedCredentials = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($credentials))
|
||||||
$ssUrl = "ss://$encodedCredentials"
|
$ssUrl = "ss://$encodedCredentials"
|
||||||
|
|
||||||
# Kill any existing sslocal process
|
# Get the process listening on the specified port and kill it if found
|
||||||
Get-Process sslocal -ErrorAction SilentlyContinue | Stop-Process -Force
|
$process = Get-ProcessByPort -port $localPort
|
||||||
|
if ($process) {
|
||||||
|
Write-Host "Killing process $($process.Id) using port $localPort"
|
||||||
|
Stop-Process -Id $process.Id -Force
|
||||||
|
}
|
||||||
|
|
||||||
# Log the sslocal restart
|
# Log the sslocal restart
|
||||||
Write-Host "Starting sslocal with method: $method, server: $server, port: $serverPort"
|
Write-Host "Starting sslocal with method: $method, server: $server, port: $serverPort"
|
||||||
@@ -68,3 +90,4 @@ while ($true) {
|
|||||||
# Wait for the next check
|
# Wait for the next check
|
||||||
Start-Sleep -Seconds $checkInterval
|
Start-Sleep -Seconds $checkInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user