A couple years ago I posted a slightly modified script for hostmonster to update the dns zone entries for subdomains. It used mechanize and ruby. However, since then my script broke as hostmonster made some changes to their backend. <a title="http://www.bradfordrobertson.com/original/dynamic-dns-hostmonster" href="http://www.bradfordrobertson.com/original/dynamic-dns-hostmonster" target="_blank">Another guy</a> made some changes that seemed to work for a while, but again it has broken. My previous post about this is <a title="http://www.jasonernst.com/posts/2012/12/18/Hostmonster-auto-update-IP-address-of-subdomain" href="/posts/2012/12/18/Hostmonster-auto-update-IP-address-of-subdomain" target="_blank">here</a>.
The culprit seems to be the mixture of javascript / ajax and the fact that hostmonster returns an empty page when you append the /ajax onto the dnszone url. No worries though, I found another way to do it.
Using Watir and Headless, it is possible to achieve the same functionality.
You need to add a few things to ubuntu to make it work:
```
sudo apt-get install ruby ruby-dev xvfb
sudo gem install watir
sudo gem install headless
```
Here's the updated script (note, you can still use the same cron jobs and ip scripts etc. from the previous two techniques.:
```
#!/usr/bin/ruby
#http://watirwebdriver.com/headless/
require "rubygems"
require "watir-webdriver"
require "headless"
IPLINK = "http://www.jasonernst.com/ip.php"
HOSTMONSTERLOGIN = "https://my.hostmonster.com/web-hosting/cplogin"
DOMAIN = "YOURDOMAIN.COM"
USER = "YOURUSERNAME"
PASS = "YOURPASS"
SUBDOMAIN = "YOUR SUBDOMAIN"
headless = Headless.new
headless.start
browser = Watir::Browser.new
browser.goto IPLINK
ip = browser.text
puts ip
puts "Logging in..."
browser.goto HOSTMONSTERLOGIN
browser.text_field(:name => 'ldomain').set USER
browser.text_field(:name => 'lpass').set PASS
browser.button(:value => 'Submit').click
puts "Done. Getting Zone Info..."
browser.goto 'https://my.hostmonster.com/cgi/dm/zoneedit'
browser.select_list(:name => 'domain_selected').select DOMAIN
Watir::Wait.until { browser.div(:id => "dns_zone_table").visible? }
puts "Done. Updating IP..."
id = browser.span(:text, /#{SUBDOMAIN}/).id
cleanid = id.delete("^0-9")
browser.span(:id => /#{cleanid}/, :class => "action_edit_link btn").click
browser.text_field(:id => /rec_sp_#{cleanid}_address/).set ip
browser.span(:id => /#{cleanid}/, :class => "action_save_link btn").click
puts "Done. Success."
headless.destroy
```