ExIP (External IP Monitor)

Description

ExIP is a “research project” to monitor and analyze my router’s (external) ip address and hostname.

A cronjob executes a simple shell script which queries (via w3m -dump_source; tried wget, but the output lacks the ip, don’t know why) the external ip from www.wieistmeineip.de. After that it gets the hostname via the host command. The results will be saved to a csv file (because it’s easy to write).

Now the “real” script comes in. It’s written in Python 3 and it converts the csv file and fills a sqlite3 database. The script is also able to create a neat html file with statistics. (Yeah, the workflow could be a bit better, but it’s only a test for now. The shell script is very small and handy and Python’s sqlite3 support is very good. I wanted to do something with sqlite3, because I was trying to learn sql.)

Displayed information

  • IP cloud (several ips are displayed; the more often the ip is in the database, the bigger it is)
  • IP/Hostname table (ordered list with all ips and hostnames)
  • Date/IP table
  • some more information about the database

A sample file is attached. (Note: The normal output isn’t masked. The sed script which masks the page is included in the tarball.)

License

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Downloads

Sample Cronjob:

# m h dom mon dow command
*/10 * * * * /usr/bin/env -i sh -c 'cd /home/stefan/Projekte/ExIP/ && sh ip.sh' > /dev/null 2>&1

(Of course, this looks ugly, but I don’t want to set $PATH by myself. If $PATH isn’t set (env -i) sh will set the variable to a proper value. The directory must be changed first, because the script writes the resulting csv file to ./ip.csv. A change of this behavior will be easy to implement if you want.)

Invocation:

python3 exip.py import [filename]

This will read the csv table from the file (or if filename isn’t set from stdin) and update the database.

python3 exip.py export [filename]

This will save a html page to the file (or if filename isn’t set print it to stdout).

Parts of this page have been generated automatically. Last update: Wed, 19 May 2010 21:40:53 +0200

Č
ċ
ď
exip-0.1.tar.gz
(3k)
Stefan Haller,
Feb 22, 2010, 11:57 AM
ċ
ď
exip-0.2.tar.gz
(3k)
Stefan Haller,
Feb 26, 2010, 12:07 PM
ċ
ď
exip-0.3.tar.gz
(4k)
Stefan Haller,
Mar 19, 2010, 10:17 AM
ċ
ď
exip_masked.html
(10k)
Stefan Haller,
Mar 19, 2010, 10:21 AM
Comments