```powershell
# PowerShell 스크립트
# 이메일 설정
$smtpServer = "smtp.example.com"
$smtpFrom = "your_email@example.com"
$smtpTo = "receiver_email@example.com"
$smtpUser = "your_email@example.com"
$smtpPassword = "your_email_password"
function Get-ExternalIP {
return (Invoke-RestMethod -Uri "https://api.ipify.org").Trim()
}
function Get-CPUUsage {
return (Get-WmiObject -Class Win32_Processor).LoadPercentage
}
function Get-InternetUsage {
$netStats = Get-NetAdapterStatistics | Measure-Object -Property ReceivedBytes, SentBytes -Sum
return $netStats.Sum.ReceivedBytes + $netStats.Sum.SentBytes
}
function Send-Email {
param (
[string]$body
)
$msg = New-Object System.Net.Mail.MailMessage
$msg.From = $smtpFrom
$msg.To.Add($smtpTo)
$msg.Subject = "System Status Update"
$msg.Body = $body
$client = New-Object Net.Mail.SmtpClient($smtpServer, 587)
$client.EnableSsl = $true
$client.Credentials = New-Object System.Net.NetworkCredential($smtpUser, $smtpPassword)
$client.Send($msg)
}
while ($true) {
$externalIP = Get-ExternalIP
$cpuUsage = Get-CPUUsage
$internetUsage = Get-InternetUsage
$emailBody = "External IP: $externalIP`nCPU Usage: $cpuUsage%`nInternet Usage: $internetUsage bytes"
Send-Email -body $emailBody
Start-Sleep -Seconds 3600 # 1시간 대기
}
```
코드 설명:
1. Get-ExternalIP: 외부 IP를 가져옵니다.
2. Get-CPUUsage: CPU 사용률을 가져옵니다.
3. Get-InternetUsage: 인터넷 사용량을 가져옵니다.
4. Send-Email: 메일을 보내는 기능을 수행합니다.
5. 무한 루프: 1시간마다 정보를 수집하고 메일로 전송합니다.
주의사항:
- 이메일 계정 및 SMTP 서버 정보를 적절히 입력해야 합니다.
- PowerShell 스크립트를 실행할 때 관리자 권한이 필요할 수 있습니다.
- 이 스크립트는 무한 루프를 실행하므로, 중단하려면 수동으로 종료해야 합니다.
'IT' 카테고리의 다른 글
| 올라마 설치법 및 젬마4 설치 ( gemma ) (0) | 2024.10.24 |
|---|---|
| 토치 설치 중 에러 (0) | 2024.10.23 |
| 파워셸에서 특정 키 입력을 감지하고 시스템에 입력 예제 (0) | 2024.07.04 |
| PowerShell에서 Ctrl+G를 누르면 "asf"를 화면에 입력할 수 있게 하는 방법 (0) | 2024.07.04 |
| 컴퓨터 후킹 by powershell (0) | 2024.07.04 |
댓글