LinuxMonday, October 30th, 2006

IPCOUNT script

It’s time for some linux stuff. Couple of months ago I was learning bash scripting. I had had a few ideas about configuring iptables, blocking ip numbers etc., so I decided to write a tool, that could help me in that task. I especially needed the ipcount tool, something like this - ipcount.

The Suse 10.1, which I was working on that time, has the ipcount, but it worked very slow and has a lots of bugs, so I wrote a bash script that do exactly the same, but faster and with simply results.

DOWNLOAD: ipcount20060807.tar.gz

SOURCE CODE:

Example of use: ./ipcount.sh 1.2.3.4-255.255.255.255

Result:

  • 1.2.3.4/30
  • 1.2.3.8/29
  • 1.2.3.16/28
  • 1.2.3.32/27
  • 1.2.3.64/26
  • 1.2.3.128/25
  • 1.2.4/22
  • 1.2.8/21
  • 1.2.16/20
  • 1.2.32/19
  • 1.2.64/18
  • 1.2.128/17
  • 1.3/16
  • 1.4/14
  • 1.8/13
  • 1.16/12
  • 1.32/11
  • 1.64/10
  • 1.128/9

Very fast, very simple, that’s what I needed…

The script have one bug, the first IP must not equal 0.0.0.0 otherwise you will see error message (division by 0).


Leave a Reply

  • Name: (required)
  • E-mail: (not required/will not be published)
  • Website:
  • Comment: (required)
  • Enter Above Code:
  • Letters left: 255
  • Note: Your comment will appear on the site within a few hours after you submit it.