Python Programs, Links and Snippetts

This page is a collection of programs (both complete and otherwise) that I like or have written. The code was written in one of three environments, being Kate, VI or Pythons own IDLE

A mild warning: This code is provided on an as-is basis and has absolutely no warranty direct or implied.

Programs

These are the programs I have written. The comments on the left are so you can see what's going on without opening the files. Many of them have good comment blocks that describe usage and sometimes history on the problem being solved.

Project Description HTML Source Plain Text Source
TCP client with encrypted communications crypclnt.html crypclnt.py
TCP server with encrypted communications crypserv.html crypserv.py
Ethphoenix. *nix only. This program is designed to run as a cron job. On first run it will read the ifconfig output and record the state of all ethernet interfaces. On subsequent running it will make sure that the state of all eth devices are returned to a last known state (up/down and IP). To re-set what Ethphoenix knows, just delete the file it creates. It will then run "as new". Ethphoenix was written to recover an ethernet interface from if/when I accidentially stopped it. It will only bring the interfaces back up. If autonegotiation screws with the connection this does not help. Works very well. ethphoenix.html ethphoenix.py
Ethphoenix2. *nix only. This program is designed to run as a cron job. On first run it will read the ifconfig and netstat output and record the state of all ethernet interfaces. On subsequent running it will make sure that the state of all eth devices are returned to a last known state (up/down, IP and duplicity). To re-set what Ethphoenix knows, just delete the file it creates. It will then run "as new". Ethphoenix was written to recover the/a machine from if/when I accidentially shutdown an eth interface. This version was to use MII-tool and ensure that the cards are up and set to the right settings. It is not finished yet. ethphoenix2.html ethphoenix2.py
Great little script for testing if your web server is running python in a CGI circumstance. index.html index.py
Multiping has been created to extend the way ping works. From the command line, you can ping a number of IPs and hostnames a given number of packets. Examples: ./multiping.py 5 192.168.1.1 (ping 192.168.1.1 with 5 packets), ./multiping.py 25 192.168.1.1 www.google.com 210.11.44.66 (pings the given hosts 25 times). Works very well, has some bugs though. multiping.html multiping.py
This script is part of a set that was used in processes to seemlessly migrate users from a proprietry (and awkward) mail server to a more open and usable mail server. This script is designed to parse a particular output from an ngrep command, place the processed data into a database and extract known probably good username/password sets. The ngrep command was designed to capture cleartext username and password sets with a timestamp. This script is considered "throw away" because once the users were migrated, there was no use for it, but I'm very proud of it. This script was my first not-testing python program and my first experience with an SQL compliant db. ngrep_analyzing_tool.html ngrep_analyzing_tool.py
*nix only. This script is part of a set that was used in processes to seemlessly migrate users from a proprietry (and awkward) mail server to a more open and usable mail server. It was designed to take a plain text file of username/password sets whitespace delimited and create MD5 hashes for the passwords and add the username/password sets without allowing shell access to the users. auto_user_add.html auto_user_add.py
This was really my first python program ever. The hangman game inspiration came from a book that was made by Creative Computing and was for programming BASIC. My challenge was to translate the BASIC hangman into Python. It was done successfully (I think). Requires a "word file" (file of words) of some sort. Those on *nix can use the dictionary word file, MS users will need to make their own (because MS products are easier to use). hmgameengine.html hmgameengine.py
This is a ripper set of files. The program itself is a crossword helper. It uses a web interface to go through a CGI script. It uses a regex to find a match within a word file and then displays a number of meanings to the word. It's kick-ass because the meanings are coming from another source. We only need a dictionary word file (the *nix default is good, but we made a better one) on the webserver, as we get the meanings from a number of other dictionary websites. Sadly it uses frames, but that was the only way we could see of getting a worthwhile interface. Thanks for your input Disad, it was a great help. crossword4.html
crosswordhtml.html
crosswordindexhtml.html
bannerhtml.html
crossword4.py
crossword.html
crosswordindex.html
banner.html
This program was designed to crawl the Bureau of Meteorology website and collect the weather observations putting them into a relational SQL database. I was planning to integrate a Growing Degrees Days (GDD) section into my horticultural website (that is not yet operational). For GDD you need weather observations along with plant growth observations. I figured I could get the weather data and just ask people for the observations on their plants. It's not entirely accurate, because of microclimate conditions, but it could be the biggest GDD project on earth. Sadly, I've got nowhere to host it yet. This script will no longer work, as the BoM have changed their format and to the text parsing I've engineered for is vastly different. html_parser.html html_parser.py

Other Peoples Code

These are the programs I like that other people have written. This code is mostly from books, one program has been shared by a friend. Often I can't remember which book it came from (unless I've credited it in the code somewhere)

Project Description HTML Source Plain Text Source
Comments in the top of this program are not familiar to me, so I suspect it's someone else's. Prints a list with the iterator being printed. hello-world.py
This code has been shared by a friend of mine. I used this code as part of a set that was used in processes to seemlessly migrate users from a proprietry (and awkward) mail server to a more open and usable mail server. This script gave me the ability to connect to an SQL aware database easily. Thanks SpLiFF. sql.html sql.py
This is from a book. It is the minimum required for a TCP connection on a client. tstclnt.py
This is from a book. It is the minimum required for a TCP connection on a server. tstserv.py
This is from the postgresql book. It connects to a database, issues a query and prints the result. postgres_client.py
This was found on the Internet. It is a soundex module conforming to Knuth's algorithm implementation 2000-12-24 by Gregory Jorgensen public domain. Soundex is cool. It is designed to boil text words down into "codes" that are considered to sound similar. EG Brad, Bread and Brett all sound similar and have the same code, so if I was looking for something that sounded like "Brett" it would return Brett, Bread and Brad. Makes a good thing for searching English words when accents are involved. soundex.html soundex.py
This was from a book. With the PythonWin32 extensions installed, you can hook into the COM and manage programs with a script. This one opens MS Word, writes something, saves it, re-opens the file, alters the text, saves the file and closes word. There is a flag to tell the program to show the window or not (yes, it can be done without the user knowing). wordcom.py

Links

Various adventures and exercises have taken me all over the internet to find worthwhile resources for whatever idea I had in my head at the time. I've found that many of my ideas are somewhat left-of-field and don't have a direct answer out there in cyber-space. Many of the websites I've come across over the years have disappeared so these are the ones I know are still alive. (2010-07-20)

I've not yet figured out how to categorize the links, so they'll remain un-sorted.

While putting these links in, I've noticed that some are a little dated. I've put them in anyway, because often the basic theories are still relevant.