Created
October 3, 2009 00:16
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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