init: ps-profile bootstrap + gper-core
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
# gper-core.psm1 — Личный модуль функций gper
|
||||
# Версия: 1.0.0
|
||||
# Дата: 2026-07-21
|
||||
|
||||
# ============================================================
|
||||
# WOL — Wake-On-LAN
|
||||
# ============================================================
|
||||
function Send-WakeOnLan {
|
||||
<#
|
||||
.SYNOPSIS Отправить магический пакет WOL по MAC-адресу.
|
||||
.EXAMPLE Send-WakeOnLan -MacAddress 'BC:24:11:AA:BB:CC'
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory, Position = 0)]
|
||||
[ValidatePattern('^([0-9A-Fa-f]{2}[:\-]){5}[0-9A-Fa-f]{2}$')]
|
||||
[string]$MacAddress,
|
||||
|
||||
[string]$BroadcastAddress = '255.255.255.255',
|
||||
[int]$Port = 9
|
||||
)
|
||||
|
||||
$mac = $MacAddress -replace '[:\-]', ''
|
||||
$bytes = [byte[]](@(0xFF) * 6 + ($mac -split '(..)' | Where-Object { $_ } | ForEach-Object { [Convert]::ToByte($_, 16) }) * 16)
|
||||
$udp = [System.Net.Sockets.UdpClient]::new()
|
||||
$udp.Connect($BroadcastAddress, $Port)
|
||||
$udp.Send($bytes, $bytes.Length) | Out-Null
|
||||
$udp.Close()
|
||||
Write-Host "WOL → $MacAddress" -ForegroundColor Green
|
||||
}
|
||||
Set-Alias -Name wol -Value Send-WakeOnLan -Option AllScope -Force
|
||||
|
||||
# ============================================================
|
||||
# SSH — быстрый доступ к узлам
|
||||
# ============================================================
|
||||
function Connect-VPS {
|
||||
<#
|
||||
.SYNOPSIS SSH на VPS по алиасу (ru/us/us2/iz/ya).
|
||||
.EXAMPLE Connect-VPS ru
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory, Position = 0)]
|
||||
[ValidateSet('ru', 'us', 'us2', 'iz', 'ya')]
|
||||
[string]$Node
|
||||
)
|
||||
$keyPath = 'c:\Users\tarakan\.ssh\ai_ssh_key'
|
||||
$ipMap = @{
|
||||
ru = '5.129.200.97'
|
||||
us = '77.91.126.90'
|
||||
us2 = '77.91.126.64'
|
||||
iz = '185.239.48.145'
|
||||
ya = '158.160.227.222'
|
||||
}
|
||||
ssh -p 63121 -i $keyPath "uai@$($ipMap[$Node])"
|
||||
}
|
||||
Set-Alias -Name vps -Value Connect-VPS -Option AllScope -Force
|
||||
|
||||
# ============================================================
|
||||
# Профиль — обновление
|
||||
# ============================================================
|
||||
function Update-GperProfile {
|
||||
<#
|
||||
.SYNOPSIS git pull в директории профиля + перезагрузить профиль.
|
||||
#>
|
||||
$profileDir = Join-Path $HOME 'Documents\PowerShell\gper-profile'
|
||||
if (-not (Test-Path $profileDir)) {
|
||||
Write-Host 'Директория профиля не найдена' -ForegroundColor Red
|
||||
return
|
||||
}
|
||||
Push-Location $profileDir
|
||||
git pull
|
||||
Pop-Location
|
||||
. (Join-Path $profileDir 'profile.ps1')
|
||||
Write-Host 'Профиль обновлён и перезагружен' -ForegroundColor Green
|
||||
}
|
||||
Set-Alias -Name reload -Value Update-GperProfile -Option AllScope -Force
|
||||
|
||||
# ============================================================
|
||||
# Утилиты
|
||||
# ============================================================
|
||||
function Get-ExternalIP {
|
||||
# Показать внешний IP (через us-vps для проверки обхода)
|
||||
(Invoke-RestMethod -Uri 'https://api.ipify.org?format=json' -TimeoutSec 10).ip
|
||||
}
|
||||
Set-Alias -Name myip -Value Get-ExternalIP -Option AllScope -Force
|
||||
|
||||
function Test-PortOpen {
|
||||
<#
|
||||
.SYNOPSIS Проверить доступность TCP-порта.
|
||||
.EXAMPLE Test-PortOpen 10.10.10.1 22
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$Host,
|
||||
[Parameter(Mandatory)][int]$Port,
|
||||
[int]$TimeoutMs = 2000
|
||||
)
|
||||
$tcp = [System.Net.Sockets.TcpClient]::new()
|
||||
$result = $tcp.BeginConnect($Host, $Port, $null, $null)
|
||||
$ok = $result.AsyncWaitHandle.WaitOne($TimeoutMs, $false)
|
||||
$tcp.Close()
|
||||
if ($ok) {
|
||||
Write-Host "$Host`:$Port OPEN" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "$Host`:$Port CLOSED / timeout" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
Set-Alias -Name portcheck -Value Test-PortOpen -Option AllScope -Force
|
||||
|
||||
Export-ModuleMember -Function * -Alias *
|
||||
Reference in New Issue
Block a user