PERL   73
iptables pl
Guest on 25th January 2023 02:03:12 AM


  1. #!/usr/bin/perl
  2. #
  3. # This is a quick perl script to
  4. # pull bandwidth usage from iptables chains
  5. #
  6. # If you use/optimize this script, please let me know.
  7. # Brian Stanback : brian [at] stanback [dot] net
  8.  
  9. # Example iptables rule for web bandwidth usage:
  10. # > iptables -N WWW
  11. # > iptables -A WWW -j ACCEPT
  12. # > iptables -A INPUT -p tcp -m tcp --dport 80 -j WWW
  13. # > iptables -A OUTPUT -p tcp -m tcp --sport 80 -j WWW
  14. #
  15. # Run "iptables.pl WWW" as root to test, note that you can
  16. # combine more than one protocol into a single chain.
  17. #
  18. # Sudo Configuration (/etc/sudoers)
  19. # > www-data    ALL = NOPASSWD: /usr/share/cacti/scripts/iptables.pl
  20. #
  21. # The Input String should be set to "sudo <path_cacti>/scripts/iptables.pl <chain>"
  22. # and you will need to setup an input field so that the <chain> argument can be passwd.
  23. #
  24. # The data input type should be set to COUNTER
  25. #
  26.  
  27. if ($ARGV[0])
  28. {
  29.         $chains = `/sbin/iptables -xnvL | grep -A 2 'Chain $ARGV[0]'`;
  30.         @chains = split(/\n/, $chains);
  31.         $chains[2] =~ /[\W+]?[0-9]+\W+([0-9]+)\W+/;
  32.         print $1;
  33. }
  34. else
  35. {
  36.         print "Usage: $0 Chain\n";
  37. }

Raw Paste

Login or Register to edit or fork this paste. It's free.