Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Server name/IP converter

When passed either an IPv4 address or the name of a domain or server, this script will return either a name or an IP, respectively.
#!/usr/bin/perl -w
use strict;
use Socket;
my $arg = shift;
if ($arg =~ /^(\d+\.){3}\d+$/) {
 print scalar gethostbyaddr(inet_aton($arg), AF_INET), "\n"
} else { printf "%vd\n", scalar gethostbyname $arg }

Get machine ID

machine-id: does [read dns://]

Getting rid of domain transfer limitations in all zone files on Ensim

An inelegant use of find and grep, but it works.

find . | grep -e "zone" | xargs perl -pi -e 's/allow-transfer {.+?}\;//'

EveryDNS update script

This script lets you update your IP address at everydns.net

#!/usr/bin/env ruby
require 'optparse' 
require 'net/http' 
require 'cgi' 

class EveryDnsUpdater
  attr_accessor :user, :pass
  attr_reader :ip, :code, :body

  def params
    @params ||= {"ver" => "0.1"}
  end
      
  def host
    "dyn.everydns.net"
  end
  
  def query
    "/index.php?" + params.collect{ |k,v| "#{k}=#{CGI.escape(v)}"}.join('&')
  end
  
  def parse(body)
    @body   = body
    @code   = @body.scan(/Exit Code: (\d+)/i).to_s.to_i
    @ip     = @body.scan(/IP now: ([\d\.]+)/).to_s
  end
      
  def run
    Net::HTTP.start(host) do |http| 

      req = Net::HTTP::Get.new(query) 
      req.basic_auth(user, pass)
      response = http.request(req)
      case response
      when Net::HTTPSuccess
        parse(response.body)
        return @code
      else
        return response.code
      end
    end
  end
end

opts = OptionParser.new 
updater = EveryDnsUpdater.new

opts.banner = "Usage: everydns [options]"
opts.separator ""
opts.on("-u", "--user=USER", "User name") { |str| updater.user = str } 
opts.on("-p", "--pass=PASS", "Password") { |str| updater.pass = str } 
opts.on("-d", "--domain=DOMAIN", "Domain name you wish to update")  { |str| updater.params["domain"] = str } 
opts.on("-a", "--address=[IP]", "IP address you want to supply") { |str| updater.params["ip"] = str } 
opts.on_tail("-h", "--help")   { puts opts; exit } 

opts.parse(ARGV)

if ARGV.empty? or updater.user.nil? or updater.pass.nil? or updater.params["domain"].nil?
  puts opts
  exit
end

if updater.run == 0
  puts "IP address set to #{updater.ip} successfully..."
else
  puts "Not successful..."
  puts updater.body
end
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS