#!/usr/bin/ruby #@author apoc #@licence gpl #@version 0.02 [Tested & Working @ 01.06.09] # nicktester tests nickname availability on different sites/systems: # google(gmail), yahoo mail, twitter, soup.io, # delicious, digg, mister wong, # youtube, # (IRC) freenode # ideas for more services? mail me: apoc at sixserv.org # you find a web frontend here: # https://apoc.sixserv.org/nicktester # required libs: (install via gems: # gem install ) # mechanize, json(1.1.6) # NOTES: # - I'm not sure the MisterWong tester works correct # TODOs/IDEAs: # - use HEAD for location based tests? # - maybe test all yahoo mail TLDs? # Changelog 0.01 -> 0.02 # - last.fm ------------------------ # - json output # - random proxy support # - 'All' as service --------------- # - flush # - rbot remote nicktester require 'rubygems' require 'mechanize' require 'cgi' require 'json' require 'socket' # settings YAHOO_MAIL_TLD = 'yahoo.de' # mailaddy to check for availability IRC_NICK = 'NickTESTER_a7' # "abstract" nicktester class with common stuff class Nicktester def initialize @agent = WWW::Mechanize.new # setting up @agent.user_agent = 'Nicktest Script; http://apoc.sixserv.org/nicktester/' end # method for testing a nickname # returns TRUE if nickname is free, FALSE if not def valid?(nickname) begin if not nickname.match /^[a-zA-Z0-9\.]+$/ puts "[ALL] Invalid Nickname." exit end return _valid?(nickname) rescue puts "An Error Occurred! Maybe #{self.class.to_s} changed something, but" puts "it is most likly temporary just try it again. The Exception Message:" puts puts "\t#{$!}" puts exit end end # must implemented by concret Nicktesters private def _valid?(nickname) raise NotImplementedError end def set_ajax_header @agent.pre_connect_hooks << lambda do |params| params[:request]['X-Requested-With'] = 'XMLHttpRequest' end end def striptags(code) code.gsub(/<[^>]+>/, '') end end class Youtube'mail', 'continue'=>'http://www.google.com', 'Email'=>nickname, 'FirstName'=>'', 'LastName'=>'', 'formId'=>'createaccount', 'inputId'=>'Email', 'dsh'=>dsh } page = @agent.get 'https://www.google.com/accounts/CheckAvailability', getrequest message = striptags(page.body) if message.match /is available/ ret[0] = true elsif message.match /is not available/ ret[0] = false elsif message.match /please type the characters you see in the image below/ ret[0] = false ret[1] = "[Google] could not check username. Please try again later." else ret[0] = false ret[1] = "[Google] i assume invalid characters/size: #{message}" end ret end end class Yahoo'yahoo_default', 'RequestVersion'=>'1', 'AccountID'=>"#{nickname}@#{YAHOO_MAIL_TLD}", 'GivenName'=>'', 'FamilyName'=>'', 'ApiName'=>'ValidateFields', 'intl'=>'de' } page = @agent.get 'https://edit.europe.yahoo.com/reg_json', get_request message = JSON.parse(page.body) if message['ResultCode'] == 'SUCCESS' ret[0] = true elsif message['ResultCode'] == 'PERMANENT_FAILURE' ret[0] = false else ret[0] = false ret[1] = '[Yahoo] JSON-Error maybe intresting' puts message.to_s if not $json end ret end end class Twitter nickname } page = @agent.post 'http://www.last.fm/ajax/nametaken/', post_request if page.body.match /false/ # nametaken ? yes(true) = false no(false) = true ret[0] = true elsif page.body.match /true/ ret[0] = false else ret[0] = false ret[1] = "[LastFm] Unknown response" puts page.body if not $json end ret end end class Diggnickname, 'token'=>token } begin page = @agent.post "http://digg.com/ajax/validate/usernameAvailable", post_request message = page.body rescue WWW::Mechanize::ResponseCodeError => error message = error.page.body end if message.match /"success":true/ ret[0] = true elsif message.match /"success":false/ ret[0] = false else ret[0] = false ret[1] = "[Digg] Strange Result" puts message if not $json end ret end end # I'm not sure this tester works correct class MisterWong30Seconds)" if not $json ircsocket = TCPSocket.new(@irc_host, @irc_port) ircsocket.puts "NICK #{IRC_NICK}" ircsocket.puts "USER #{IRC_NICK} 8 * :nicktest.rb (http://apoc.sixserv.org/scripts/nicktest.rb)" # TODO: #{`whoami`.chop} as USER ? while line = ircsocket.gets break if line.match /^:[^ ]+ 376 / end ircsocket.puts "PRIVMSG NickServ :INFO #{nickname}" valid = nil while line = ircsocket.gets # TODO: maybe parse Last seen (you could let a Staffer drop the nick in Freenode) if line.match /Information on / valid = false break elsif line.match /is not registered./ valid = true break end end ircsocket.close if valid == nil ret[1] = "[NickServTester] Could not get a result." valid = false end ret[0] = valid ret end end class Freenode [<[+/-]service>] [--json] the nickname that sould be tested. valid chars: A-Z a-z 0-9 . (Optional, -All) exclude services with - #{joinwrap services, 50, 14} --json Enable JSON Output. Example: #{$0} neo -All +Freenode EOS exit end nickname = ARGV[0] # -json ? $json = false if ARGV.last == '--json' $json = true ARGV.pop end if ARGV.length > 1 ARGV.delete_at 0 ARGV.each_index do |idx| service = String.new ARGV[idx] op = true # true = + false = - if service.match /^([-+])/ op = ($1 == '+' ? true : false) service.gsub! /^([-+])/, '' end if not services_static.include? service and service != 'All' puts "Service #{service} not supported. Mail your ideas: apoc at sixserv.org" exit end if service == 'All' if op services = Array.new services_static else services = [] end end if not op services.delete service else services << service end end end puts "Test the availability of '#{nickname}' at #{joinwrap services, 50, 0}" if not $json services.each do |service| if $json print "{\"#{service}\":" else puts "Testing... #{service}..." end ret = Object::const_get(service).new.valid? nickname if ret.length < 2 ret[1] = '' end if $json print "{\"result\":#{ret[0].to_s},\"msg\":\"#{ret[1]}\"}" else if ret[0] puts "=> \e[0;32m[FREE]\e[m (#{ret[1]})" else puts "=> \e[0;31m[TAKEN]\e[m (#{ret[1]})" end puts end puts "}" if $json $stdout.flush end puts puts #EOF