Detta skript uppdaterar angivna värdnamn i DynDNS.
|
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# $MyInvocation.MyCommand.Source # # Write-Host -NoNewLine 'Press any key to continue...'; # $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); # # exit if ( $host.name -eq "Windows PowerShell ISE Host" ) { # Skript exekverat i ISE $scriptnamefullpath = $psISE.CurrentFile.FullPath } else { $scriptnamefullpath = $MyInvocation.MyCommand.Source } $logfilefullpath = $scriptnamefullpath.Replace(".ps1","-$(Get-Date -Format "yyMMdd").log") if ( -not (Test-Path $logfilefullpath) ) { New-Item -Type File -Path $logfilefullpath } #Your info goes here $hostnames = @("example.com","www.example.com","anotherhost.example.com") $user = "example.com" # (Get-Credential).Password | ConvertFrom-SecureString $secstrpwd = "01000000d08c9ddf0115d1118c7a00c04fc297eb01000000be4510bfa4fa3340bda7e3005c3c30d300000000020000000000106600000001000020000000963c91df31dc44d1cb969aba0ef1440744c196d7ee90e019b0b2adb31ef7cabe000000000e800000000200002000000080fac7dc647d8a05b2143c3a8b76c62b774afa799073dcd1368845aed7457ca3200000000e64b1becdcdbffac4aeb9f67aac0edb283a21d75f9c3f4c71f03124a07c31c640000000f411d980109154251827c7788562f96fcb36e8c991b3f3351fe2c0f661b98b80969b059c7844298d03e60aa4e78a3f362db6a802900b1e1003654af7a00b26c8" #Force TLS 1.2 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #Get a page with your current IP # CHECK YOUR ISP FOR CORRECT USER AND CONNECTION INFO $MyIpPage = Invoke-WebRequest "https://dyndns.example.com/checkip" #Make sure we got a IP back in the response If ($MyIpPage -match "(?:[0-9]{1,3}.){3}[0-9]{1,3}") { $myIp = $Matches[0] #Create a set of credentials #$secpasswd = ConvertTo-SecureString $pwd -AsPlainText -Force $secpasswd = ConvertTo-SecureString $secstrpwd $mycreds = New-Object System.Management.Automation.PSCredential ($user, $secpasswd) Clear-DnsClientCache foreach ( $hostname in $hostnames) { $OldIP = (Resolve-DnsName -NoHostsFile -Name $hostname).IPAddress #[System.Net.Dns]::GetHostAddresses(“$hostname”).IPAddressToString if( $MyIP -ne $OldIP) { $dateStr = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $logStr = "$($dateStr) : Result of lookup: $($hostname) = $($OldIP), IPs NOT matching for $($hostname), registering $($myIp)" $logStr >> $logfilefullpath #Build up the URL $url = "https://dyndns.example.com/?hostname=$hostname&myip=$myIp" #Invoke the URL $resp = Invoke-WebRequest -Uri $url -Credential $mycreds $resp.Content #Expected answers that I found "good","nochg","nohost","badauth","notfqdn" #> }else{ #$dateStr = Get-Date -Format "yyyy-MM-dd HH:mm:ss" #$logStr = "$($dateStr) : Result of lookup: $($hostname) = $($OldIP), IPs matching for $($hostname), DOING NOTHING!" #$logStr >> $logfilefullpath } } } Else { #fake response if we didn't get any IP "NoDynIP" } $dateStr = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $logStr = "$($dateStr) : Script completed" $logStr >> $logfilefullpath |