#!/usr/bin/ruby # f2b.rb # F2B a simple script to display banned IPs in iptables # # Notice: you need to have figlet installed on your system # $ sudo apt-get install figlet require 'terminal-table' require 'colorize' def iptables_to_array res = %x(iptables -L -n) #Fetch iptables rules arr = [] res.each_line{|s| arr << s[/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/]} #Get ips in each lines arr.reject! { |e| e.to_s.empty? } #We delete nil or empty values arr.delete("0.0.0.0") #We do not banned all the world ;-) return arr.uniq! #And finally we do want only unique IPs end #### THIS BEGINS puts %x(figlet "Banned!") arr = iptables_to_array puts "Currently we banned ".colorize(:color => :black, :background => :yellow) + arr.count.to_s.colorize(:color => :white, :background => :red) + " IP's!!!".colorize(:color => :black,:background => :yellow) + "\n" # We display Ips in a fancy table table = Terminal::Table.new table.headings = ["All 0f FaMe".yellow] arr.each do |ip| table.add_row [ip] end puts table