Skip to content

Instantly share code, notes, and snippets.

@johnl
Created June 8, 2012 17:29
Show Gist options
  • Save johnl/2897076 to your computer and use it in GitHub Desktop.
Save johnl/2897076 to your computer and use it in GitHub Desktop.
xip.io implementation with powerdns_pipe in ruby
launch=pipe
pipe-command=/path/to/xipio-pipe.rb
pipe-timeout=200
pipe-regex=^.*.ip.ipq.co;.*$
#!/usr/bin/env ruby
require 'rubygems'
require 'powerdns_pipe'
require 'ipaddr'
# *.10.0.0.1.ip.ipq.co
ipre = Regexp.new('^(.*?)([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\.ip\.ipq\.co$')
# *.abc123.ip.ipq.co
wildre = Regexp.new('^(.+)\.([A-Za-z0-9]{3,7})\.ip\.ipq\.co$')
# abc123.ip.ipq.co
ipsre = Regexp.new('^([A-Za-z0-9]{3,7})\.ip\.ipq\.co$')
pipe = PowerDNS::Pipe.new :banner => 'ip.ipq.co pipe'
pipe.run! do
if m = ipre.match(question.name)
ip = IPAddr.new(m[2])
case question.qtype
when "CNAME", "ANY"
answer :name => question.name , :type => 'CNAME', :ttl => 3600,
:content => "#{ip.to_i.to_s(36)}.ip.ipq.co"
end
elsif m = wildre.match(question.name)
case question.qtype
when "CNAME", "ANY"
answer :name => question.name , :type => 'CNAME', :ttl => 3600,
:content => "#{m[2]}.ip.ipq.co"
end
elsif m = ipsre.match(question.name)
ip = IPAddr.new(m[1].to_i(36), Socket::AF_INET)
case question.qtype
when "A", "ANY"
answer :name => question.name , :type => 'A', :ttl => 3600,
:content => ip.to_s
end
end
end
@glaszig
Copy link

glaszig commented Jun 14, 2012

well, i should try such things on different networks before posting -- works from outside the office.
no, forcing v4 doesn't help. it seems to be something else with our gateway. the same with xip.io.

thank you for turning my head ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment