Skip to content

Instantly share code, notes, and snippets.

@FiXato
Created October 3, 2009 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FiXato/200274 to your computer and use it in GitHub Desktop.
Save FiXato/200274 to your computer and use it in GitHub Desktop.
Gets list of hosts from the Anope services logs based on successful nickserv identifies.
#!/usr/bin/env ruby
# get_hosts_by_identified_nicks.rb
# Gets a list of hosts from the Anope services logs based on successful nickserv identifies.
require 'set'
SERVICES_LOGS_PATH = File.expand_path("~/services/data/logs/services.log*")
DEBUG = false
if ARGV.size > 0
DEBUG = true if ARGV.include?('--debug')
nicks = ARGV
else
nicks = ARGF.readlines
end
if nicks.size == 0
puts('Get a list of hosts from the Anope services logs based on successful nickserv identifies.')
abort('Usage: get_hosts_by_identified_nicks nick [nick-2] [..] [nick-n]')
end
all_hosts = Set.new
identify_lines = `grep "identified for nick" #{SERVICES_LOGS_PATH}`.squeeze(' ').split("\n")
#identify_lines.map!{|l|l.slice!(0..l.index(']'));l.gsub('[','').gsub(']','').strip} unless DEBUG
nicks.each do |nick|
nick.strip!
results = identify_lines.select{|l|l.downcase.include?('identified for nick %s' % nick.downcase)}
results.each do |line|
next unless line[-(nick.length)..-1].downcase == nick.downcase
puts line if DEBUG
line.slice!(0..line.index(']'));line.gsub('[','').gsub(']','').strip
host = line.strip.split(' ')[1].split('@')[1]
all_hosts << host
end
end
puts all_hosts.to_a.sort.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment