Being away for about a year now due to lack of time I believe it's the right time to get back into writing.
I wrote a simple utility a while ago to convert CIDR addresses to IP ranges and the other way around (in the C programming language). In addition, it can perform IP matching against CIDR/IP ranges. You can grab the utility here.
Compile the code with:
gcc -DNDEBUG -Wall -W -O2 iptool.c -o iptool
Expand a CIDR address to an IP range:
# ./iptool range 212.251/17
212.251.0.0 - 212.251.127.255
Convert an IP range to a CIDR address:
# ./iptool cidr 212.251.0.0 212.251.127.255
212.251.0.0/17
Match a single IP address against a CIDR address:
# ./iptool cmatch 212.251.0.0/17 212.251.31.59
IP match
Match a single IP address against an IP range:
# ./iptool rmatch "212.251.0.0 - 212.251.127.255" 212.251.31.59
IP match
Parts of the source code may come in handy when writing IP related applications/utilities.
For quite some time I was using the mrtg tool by Tobi Oetiker to graph many aspects of my network and other sources like number of connections on my servers. It is a great tool but has some limitations, you can have only two data sources and you can't specify the data average resolution for say, more htan 19 months (to name some). Another limitation is the data collection interval which can not be set to be less than 5 minutes.
Probably there are workarounds here and there for these limitations but why bother when there is another great tool by the same author which does not have the above limitations and is much more powerful?
Recently I used the rrdtool in conjunction with php in order to make some graphs to monitor the activity on one of my servers. In this howto I describe how to graph the number of people on two servers into the same graph (Two Data Sources) but with rrdtool one can graph any kind of values with an arbitrary number data sources which can be retrieved at specific intervals. If you are not familiar with rrdtool please take a look at the following two perfect introduction tutorials, since I am not going to cover everything in detail here for rrdtool:
Note: Tested on a debian system, I can't guarantee that this will work for your system
Installing the latest version of rrdtool and php-rrdtool module
Fist of all ensure that php and php-dev packages are installed on your system. On a debian-like system use the following command:
apt-get install php5 php5-cli php5-dev
First we should get the librrd-dev package to ensure that all dependencies are installed using the command:
apt-get install librrd-dev
I always like to use the latest stable versions for all the software packages I use, you can use the following commands to download and install rrdtool (version 1.3.7 as of this writing):
cd /tmp/
wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.3.7.tar.gz
tar zxf rrdtool-1.3.7.tar.gz
cd /tmp/rrdtool-1.3.7
./configure --prefix=/usr/local/rrdtool-1.3.7
make
make install
Now rrdtool should be installed at /usr/local/rrdtool-1.3.7
It's time to compile the rrdtool php module using the following commands:
cd /tmp/
wget http://oss.oetiker.ch/rrdtool/pub/contrib/php_rrdtool.tar.gz
tar zxf php_rrdtool.tar.gz
cd /tmp/rrdtool
/usr/bin/phpize
./configure --with-rrdtool=/usr/local/rrdtool-1.3.7 --with-php-config=`which php-config`
make
make install
The file rrdtool.so should be installed at /usr/lib/php5/20060613+lfs/ (or something similar)
We must now enable the module for php:
/bin/echo "# Enable the rrdtool module
extension=rrdtool.so" \
| /usr/bin/tee /etc/php5/conf.d/rrdtool.ini
If you want to enable the module for apache's php module and not only php command line (php-cli), use the following command:
/etc/init.d/apache2 restart
Now ensure that the module is enabled:
php -r 'phpinfo();' | grep -i "rrdtool.*extension"
It should output something like this:
<h1 class="p">rrdtool Version 1.2.x extension</h1>
That's it for the php-rrdtool module
To be continued...
Hello, this is my first post on my brand new blog. I have made this blog mainly for myself, in order to keep some notes and howtos but I will present them as tutorials whenever possible. I will also make various posts about programming, since I'm very interested about it and it's also my work.
I hope you will find it interesting