-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathss2ssh.ps1
More file actions
55 lines (44 loc) · 1.64 KB
/
Copy pathss2ssh.ps1
File metadata and controls
55 lines (44 loc) · 1.64 KB
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
50
51
52
53
54
55
function ss2ssh {
param(
[Parameter(Mandatory=$true)]
[string]$sshTarget
)
# Load library Windows Forms & Drawing
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Ambil gambar dari clipboard
$img = [Windows.Forms.Clipboard]::GetImage()
if ($null -eq $img) {
Write-Error "Clipboard tidak berisi gambar. Gunakan Win+Shift+S atau Alt+PrintScreen."
return
}
# Validasi dimensi gambar
if ($img.Width -eq 0 -or $img.Height -eq 0) {
Write-Error "Clipboard berisi gambar invalid."
return
}
# Konversi ke PNG dalam memory stream
$ms = New-Object IO.MemoryStream
$img.Save($ms, [Drawing.Imaging.ImageFormat]::Png)
# Ambil timestamp epoch (Windows compatible)
$ts = [int][double]((Get-Date) - [datetime]'1970-01-01').TotalSeconds
# Encode gambar ke Base64
$b64 = [Convert]::ToBase64String($ms.ToArray())
# Buat SSH process
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = "ssh"
$psi.Arguments = "$sshTarget cat | base64 -d > /tmp/ss-$ts.png"
$psi.RedirectStandardInput = $true
$psi.UseShellExecute = $false
$psi.CreateNoWindow = $true
# Start process
$proc = [System.Diagnostics.Process]::Start($psi)
# Kirim base64 ke SSH stdin
$sw = New-Object System.IO.StreamWriter($proc.StandardInput.BaseStream, [Text.Encoding]::ASCII)
$sw.Write($b64)
$sw.Close()
# Tunggu proses selesai
$proc.WaitForExit()
# Informasi sukses (perbaikan kurung kurawal untuk variabel)
Write-Host "Screenshot berhasil dikirim ke ${sshTarget}: /tmp/ss-$ts.png"
}