mám script, ktorý kontroluje vonkajšiu IP adresu a v príapde jej zmeny mi posiela mailom novú IP.
Potrebujem do toho scriptu dorobiť časť, ktorá by mi tú IP adresu odoslala na server, kde sa pomocou PHP scriptu uloží do databázy.
V podstate potrebujem, aby PowerShell len zavolal adresu: http://www.pablox.net/writeip.php?ip=zistena_IP
Kód: Vybrať všetko
$scriptpath = $MyInvocation.MyCommand.Definition
[string]$dir = Split-Path $scriptpath
set-location $dir
$oldip = gc .\ip.txt
Write-Host "Your previous IP was: $oldip"
$currentip = (New-Object net.webclient).downloadstring("http://api.ipify.org")
while ($currentip -eq '') {$currentip = (New-Object net.webclient).downloadstring("http://api.ipify.org")}
Write-Host "Your current IP is: $currentip"
$smtpServer = "smtp.websupport.sk"
$sender = "sender@sender.net"
$users = "receiver@gmail.com";
$subject = "Your IP $currentip"
$body = "Previous IP was $oldip"
if ($oldip -ne $currentip) {
foreach ($user in $users) {
Write-Host "Sending email notification to $user" -ForegroundColor Green
$smtp = New-Object Net.Mail.SmtpClient($smtpServer, 587)
$smtp.EnableSsl = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential("mail@mail.com", "mail_pwd");
$smtp.Send($sender, $user, $subject, $body)
}
}
$currentip | Out-File .\ip.txt -Force
Write-Host "New IP saved in file is: $currentip"
Ďakujem.