Guest User

Untitled

a guest
Jul 8th, 2020
512
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #your ip at : myhostname.mydomain es: my.mydns.com
  2.  
  3. #domain
  4. $mydomain = "yourdomain.com"
  5. #Production on godaddy https://developer.godaddy.com/keys
  6. $myhostname = "my"
  7. #pubkey:privatekey
  8. $gdapikey = "9Q7p8YLDzVg_MCggBvJXYBCPRsKCP3KzSL:5KDtXPfgRxQH2uD9pa1HBW"
  9.  
  10. #log
  11. $logfile = "log.txt"
  12. Add-Content $($logfile) 'starting deamon..'
  13.  
  14. $myip = Invoke-RestMethod -Uri "https://api.ipify.org"
  15. $dnsdata = Invoke-RestMethod -Uri "https://api.godaddy.com/v1/domains/$($mydomain)/records/A/$($myhostname)" -Headers @{ Authorization = "sso-key $($gdapikey)" }
  16. $gdip = $dnsdata.data
  17.  
  18. #clear log if it's too long
  19. $nlines = 0;
  20. # Read file by 1000 lines at a time
  21. gc $logfile -read 1000 | % { $nlines += $_.Length };
  22. [string]::Format("{0} has {1} lines", $logfile, $nlines)
  23. if ($nlines -gt 2000){
  24. Clear-Content $($logfile)
  25. Add-Content $($logfile) 'Log cleared.'
  26. }
  27.  
  28. #log and output
  29. $log1 = "$(Get-Date -Format 'u') - Current External IP is $($myip), GoDaddy DNS IP is $($gdip)"
  30. Add-Content $($logfile) $log1
  31. Write-Output $log1
  32.  
  33. if ( $gdip -NotMatch $myip ) {
  34.  
  35. Invoke-RestMethod -Method PUT -Uri "https://api.godaddy.com/v1/domains/$($mydomain)/records/A/$($myhostname)" -Headers @{ Authorization = "sso-key $($gdapikey)" } -ContentType "application/json" -Body "[{`"data`": `"$($myip)`"}]";
  36.  
  37. Add-Content $($logfile) "IP has changed!! Updating on GoDaddy from $($gdip) to new: $($myip) "
  38. Write-Output "IP has changed!! Updating on GoDaddy"
  39.  
  40. }else
  41. {
  42. Add-Content $($logfile) 'No updates to do!'
  43. Write-Output "No updates to do!"
  44. }
RAW Paste Data