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
@johnl
Copy link
Author

johnl commented Jun 8, 2012

This is running now on http://ipq.co

$ host whatever.10.0.0.5.ip.ipq.co
whatever.10.0.0.5.ip.ipq.co is an alias for 2rvxtx.ip.ipq.co.
2rvxtx.ip.ipq.co has address 10.0.0.5

uses powerdns_pipe btw: https://github.com/johnl/powerdns_pipe

@glaszig
Copy link

glaszig commented Jun 14, 2012

$ dig +short whatever.10.0.0.5.ip.ipq.co

2rvxtx.ip.ipq.co.
10.0.0.5

$ dig +short whatever.192.168.178.36.ip.ipq.co

;; connection timed out; no servers could be reached

huh?

@johnl
Copy link
Author

johnl commented Jun 14, 2012

glaszig: works for me just fine. Do you have a broken ipv6 setup perhaps? Try enforcing ipv4:

dig +short -4 whatever.192.168.178.36.ip.ipq.co

@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