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

About this user

Sergey http://haqu.net

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

Domains Availability Checker

/*
This script uses whois program to check domain for "No match" record.
Example of usage:
$ ./ava.rb ruby{,-}snippets rubyzone.*
- rubysnippets.com
+ ruby-snippets.com
- rubyzone.com
- rubyzone.net
- rubyzone.org
*/

#!/usr/bin/env ruby -w

if ARGV.empty?
  puts <<-T
domains availability checker by haqu
usage: ./ava.rb url[.tld|.*] ...
  T
  exit
end

domains = []

ARGV.each do |d|
  if d.include?(".*")
    dset = d.gsub(/\*/,"")
    domains << [ "#{dset}com", "#{dset}net", "#{dset}org" ]
  else
    domains << d
  end
end
domains.flatten!

domains.each do |d|
  res, domain = "-", d
  unless domain.include?(".")
    domain += ".com"
  end
  whois = `whois #{domain}`
  res = "+" if whois.include?( "No match" )
  puts "#{res} #{domain}"
end

IP Location on Google Maps

/*
Example of usage:
$ ./lip.rb snippets.dzone.com
. Hostname: snippets.dzone.com
. Country Code: US
. Country Name: United States
. Region: CA
. Region Name: California
. City: Los Angeles
. Postal Code: 90017
. Latitude: 34.0530
. Longitude: -118.2642
. ISP: CoreExpress
. Organization: CoreExpress
. Metro Code: 803
. Area Code: 213
. Google Maps URL: http://maps.google.com/maps?q=34.0530,+-118.2642&iwloc=A&hl=en
*/

#!/usr/bin/env ruby -w

if ARGV.empty?
  puts <<-T
Locate IP by haqu
usage: ./lip.rb ip|domain ...
  T
  exit
end

require 'net/http'
require 'uri'

uri = URI.parse('http://www.maxmind.com/app/locate_ip')
res = Net::HTTP.post_form(uri,
  { 'ips' => ARGV.join(' '),
    'type' => '', 'u' => '', 'p' => ''
  } )
fstr = res.body

fstr.gsub!("Edition Results<\/span><p>","CHECKPOINT")
fstr =~ /CHECKPOINT(.+?)<\/table>/m
fields = $1.grep(/<(th|td)>/)
fields.each do |f|
  f.strip!
  f.gsub!(/<[^>]+>/,"")
end

(0...13).each do |i|
  puts ". #{fields[i]}: #{fields[i+13]}"
end

maplink = "http://maps.google.com/maps?q=#{fields[20]},+#{fields[21]}&iwloc=A&hl=en"
puts ". Google Maps URL: #{maplink}"
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS