Tweetegy On the edge of chaos with Blockchain, Dapps, DeFi, JavaScript

| About | Search | Archive | Github | RSS |

Update ZoneEdit NameServers via a Restful API in Ruby

I recently had to programmatically alter entries in ZoneEdit. While there is some documentation, it is difficult to get started quickly. This is especially true if you want to use Ruby since there are no examples written in Ruby that I could find. So I wrote a simple class to do just what I need and here it is:

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
require 'net/http'
require 'net/https'
require 'uri'

class ZoneEdit

	#Initialize with the ZoneEdit username and password credentials
	def initialize(username, password)
		@@username = username
		@@password = password
	end

	#This method can be used to change a dns record in ZoneEdit
	#Pass in the account username and zone you want to manage as well as the dnsfrom (sub-domain) forward address and 0 or 1 to shadow (cloak) or not
	def web_forward(user,zone,dnsfrom,forward,shadow)
		return send_command("command=ChangeRecord&user=#{user}&zone=#{zone}&type=WF&dnsfrom=#{dnsfrom}&forward=#{forward}&shadow=#{shadow}")
	end

	private
	def send_command(command)
		puts "https://www.zoneedit.com/auth/admin/command.html?#{command}"
		@http=Net::HTTP.new('www.zoneedit.com', 443)
		@http.use_ssl = true
		@http.start() {|http|
			req = Net::HTTP::Get.new("/auth/admin/command.html?#{command}")
			req.basic_auth @@username, @@password
			response = http.request(req)
			print response.body
		}
	end

end

It’s usage is simply as follows:

1
2
ze = ZoneEdit.new("someuser", "apassword")
ze.web_forward "someuser", "somedomain.com", "somesubdomain", "http://anewdomain.com", "1"