LScarpinati

display banned IPs in iptable

Oct 26th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.05 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. # f2b.rb
  4. # F2B a simple script to display banned IPs in iptables
  5. #
  6. # Notice: you need to have figlet installed on your system
  7. #         $ sudo apt-get install figlet
  8.  
  9. require 'terminal-table'
  10. require 'colorize'
  11.  
  12. def iptables_to_array
  13.   res = %x(iptables -L -n) #Fetch iptables rules
  14.   arr = []
  15.   res.each_line{|s| arr << s[/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/]} #Get ips in each lines
  16.   arr.reject! { |e| e.to_s.empty? } #We delete nil or empty values
  17.   arr.delete("0.0.0.0") #We do not banned all the world ;-)
  18.   return arr.uniq! #And finally we do want only unique IPs
  19. end
  20.  
  21. #### THIS BEGINS
  22.  
  23. puts %x(figlet "Banned!")
  24.  
  25. arr = iptables_to_array
  26.  
  27. puts "Currently we banned ".colorize(:color => :black, :background => :yellow) +
  28.      arr.count.to_s.colorize(:color => :white, :background => :red) +
  29.      " IP's!!!".colorize(:color => :black,:background => :yellow) + "\n"
  30.  
  31. # We display Ips in a fancy table
  32. table = Terminal::Table.new
  33. table.headings = ["All 0f FaMe".yellow]
  34. arr.each do |ip|
  35.   table.add_row [ip]
  36. end
  37.  
  38. puts table
Advertisement
Add Comment
Please, Sign In to add comment