Un buscador de texto , sirve para encontrar archivos que contengan cierto patron.
#!usr/bin/ruby
#FinderText 0.1
#Coded By Doddy H

def openwords(file)
  if File.file?(file)
    ar = File.open(file)
    lineas = ar.readlines
    ar.close
    return lineas
  end
end

def escalar(dir,text)
  files = Dir.new(dir).entries
  files.each do |file|
    if File.file?(dir+"/"+file)
      contador = 0
      words = openwords(dir+"/"+file)
      words.each do |word|
      word = word.chomp
      contador+=1
      if word=~/#{text}/
        parteuno = dir+"/"+file
        patron = File.basename(__FILE__) 
        if not parteuno=~/#{patron}/
          print "[+] File Found : "+dir+"/"+file+" in line #{contador}\n"
        end        
      end
    end
    else
      if file != "." and file != ".." and file != File.basename(__FILE__) 
        escalar(dir+"/"+file,text)
      end
    end
  end
end

def sintax()
  print "\n[+] sintax : ruby findertext.rb <directory> <text>\n"
end

def head()
  print "\n-- == FinderText 0.1 == --\n\n"
end

def copyright()
  print "\n\n(C) Doddy Hackman 2012\n\n"
end

head()

dir = ARGV[0]
text = ARGV[1]

if !dir and !text
  sintax()
else
  print "\n[+] Starting the search\n\n\n"
  escalar(dir,text)
  print "\n\n[+] Finished\n\n"
end

copyright()
    
# The End ?
Responder

Volver a “Otros lenguajes de Scripting”