Advertisement
rfrancisco

Untitled

Jul 4th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #################################################################
  4. ## ChangeIP.com bash update script ##
  5. #################################################################
  6. ## Written 3/18/09 by Tom Rinker, released to the Public Domain##
  7. #################################################################
  8. ## This is a simple bash script to preform a dDNS update with ##
  9. ## ChangeIP.com. It uses only bash and wget, and so should be ##
  10. ## compatible with virtually any UNIX/Linux based system with ##
  11. ## bash. It is intended to be executed as a cron job, and ##
  12. ## will only execute an update of dDNS records when the IP ##
  13. ## address changes. As ChangeIP.com dDNS records have a 5 min ##
  14. ## Time-To-Live, it is basically pointless and wasteful to ##
  15. ## execute it more often than every 5 minutes. This script ##
  16. ## supports logging all activity, in 3 available log levels, ##
  17. ## and supports simple management of log file size. ##
  18. #################################################################
  19. ## To use this script: ##
  20. ## 1) set the variables in the script below ##
  21. ## 2) execute the script as a cron job ##
  22. #################################################################
  23. ## WARNING: This script has two potential security holes. ##
  24. ## First, the username and password are stored plaintext in ##
  25. ## the script, so a system user who has read access to the ##
  26. ## script could read them. This risk can be mitigated with ##
  27. ## careful use of file permissions on the script. ##
  28. ## Second, the username and password will show briefly to other##
  29. ## users of the system via ps, w, or top. This risk can be ##
  30. ## mitigated by moving the username and password to .wgetrc ##
  31. ## This level of security is acceptable for some installations ##
  32. ## including my own, but may be unacceptable for some users. ##
  33. #################################################################
  34.  
  35. ################ Script Variables ###############################
  36. IPPATH=/var/log/IP # IP address storage file
  37. TMPIP=/tmp/tmpIP # Temp IP storage file
  38. LOGPATH=/var/log/changeip.log # Log file
  39. TEMP=/tmp/temp # Temp storage file
  40. CIPUSER=rafael31@gmail.com # ChangeIP.com Username
  41. CIPPASS=alex31 # ChangeIP.com Password
  42. CIPSET=1 # ChangeIP.com recordset
  43. LOGLEVEL=2 # 0=off,1=normal,2=verbose
  44. LOGMAX=500 # Max log lines, 0=unlimited
  45. #################################################################
  46.  
  47. # get current IP from ip.changeip.com, and store in $TEMP
  48. wget -q -U "rinker.sh wget 1.0" -O $TEMP ip.changeip.com
  49.  
  50. # parse $TEMP for the ip, and store in $TMPIP
  51. grep IPADDR < $TEMP | cut -d= -s -f2 | cut -d- -s -f1 > $TMPIP
  52.  
  53. # compare $IPPATH with $TMPIP, and if different, execute update
  54. if diff $IPPATH $TMPIP > /dev/null
  55. then # same IP, no update
  56. if [ $LOGLEVEL -eq 2 ]
  57. then # if verbose, log no change
  58. echo "--------------------------------" >> $LOGPATH
  59. date >> $LOGPATH
  60. echo "No Change" >> $LOGPATH
  61. echo -e "IP: \c" >> $LOGPATH
  62. cat $IPPATH >> $LOGPATH
  63. fi
  64. else # different IP, execute update
  65. wget -q -U "rinker.sh wget 1.0" -O $TEMP --http-user=$CIPUSER --http-password=$CIPPASS "https://nic.changeip.com/nic/update?cmd=update&set=$CIPSET"
  66. if [ $LOGLEVEL -ne 0 ]
  67. then # if logging, log update
  68. echo "--------------------------------" >> $LOGPATH
  69. date >> $LOGPATH
  70. echo "Updating" >> $LOGPATH
  71. echo -e "NewIP: \c" >> $LOGPATH
  72. cat $TMPIP >> $LOGPATH
  73. if [ $LOGLEVEL -eq 2 ]
  74. then # verbose logging
  75. echo -e "OldIP: \c" >> $LOGPATH
  76. cat $IPPATH >> $LOGPATH
  77. cat $TEMP >> $LOGPATH # log the ChangeIP.com update reply
  78. fi
  79. fi
  80. cp $TMPIP $IPPATH # Store new IP
  81. fi
  82.  
  83. # if $LOGMAX not equal to 0, reduce log size to last $LOGMAX number of lines
  84. if [ $LOGMAX -ne 0 ]
  85. then
  86. tail -n $LOGMAX $LOGPATH > $TEMP
  87. cp $TEMP $LOGPATH
  88. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement