A sample BASH CGI script for collecting IPs of your colleagues in your network.
Prerequisites
1) apache/cgi configuration
2) a Mysql installation
Then create script “getip.sh” under “/var/www/cgi-bin/” ( set location of cgi-bin directory as per the apache configuration)
#!/bin/bash
#Getting IP address CGI-BASH-script
#Jadu Saikia http://unstableme.blogspot.com/
#MySQL settings
# MHOME= ( location of mysql binary)
MHOME=/usr/local/mysql/bin
HOST=127.0.0.1
USER=root
PASS=”"
DB=mydb
OWNER=$(echo “$QUERY_STRING” |awk -F “=” ‘{print $NF}’)
IP=$REMOTE_ADDR
#QUERY_STRING = Query information that follows the ? in the URL that referenced this script.
#REMOTE_ADDR = IP address of the remote host making the request
#HTML Output
echo “Content-type: text/html”
echo “”
echo “<html><head><title>YOUR IP</title></head><body><h1>I am collecting the IPs</h1><pre>”;
echo “IP: <em>$IP</em><br />”
echo “You Are IP is : <em>$OWNER</em><br />”
$MHOME/mysql -u$USER -h$HOST –password=$PASS -e “INSERT INTO mydb.ips(rdate,ip,owner) VALUES(NOW(),’$IP’,'$OWNER’)” $DB
echo “</pre></body></html>”;
Then
Create MySql Database for storing the data.
logon to mysql
mysql -u root -p password
create database and table
create database mydb
use mydb
create table mydb.ips ( rdate DATE, ip VARCHAR(20) NOT NULL PRIMARY KEY, owner VARCHAR(25));
exit
Suppose the IP of the box where you are running the cgi is “172.22.22.188″ (your local ip).
Now construct the urls for your colleagues this way:
http://172.22.22.188/cgi-bin/getip.sh?owner=alexm
http://172.22.22.188/cgi-bin/getip.sh?owner=nsarma
…
…
And send them the individual urls in mail with a request to click the url (just to help you collecting the ips in the mysql table)
Once they click, your database table will be automatically populated with datas like this:
mysql> select * from mydb.ips;
+————+—————+
| rdate | ip | owner |
+————+—————+———+
| 2007-01-02 | 172.22.22.111 | alexm |
| 2007-01-03 | 172.22.22.92 | nsarma |
+————+—————+———+
2 rows in set (0.00 sec)

















