Tag Archives: programming

Multiprocess FOAF fetching with python and rdflib.

Today I’m going to share a little python script, mostly because I’ve been looking for examples on how to do this, and surprise surprise I have found none.

What this script does is to first fetch all foaf:name relations from a list of FOAF cards, and then to display these relations in a friendly manner (e.g. “John Doe knows Jane Doe.”). To do so, the script takes advantage of python’s multiprocessing libraries (Pool, to be more precise), as well as a neat little library called RDFlib. In order to perform SPARQL queries, you need to install the companion rdfextras package which includes a SPARQL plugin implementation:

$ sudo easy_install rdfextras

read more »

vim as hex editor?

Yes..who would have thought?

Being a vim user, I hoped it would be able to edit hex files. I didn’t know for sure if it can do it or not so I decided to start digging into the manuals. This nice feature of vim has proven to be really important for me lately, now that I’m testing a protocol by modifying valid pcap files.
read more »

Combining inotify and python with pyinotify

While working on a python project recently, I got to the point where I had to monitor a file for modifications. For example, I want to monitor an sqlite database (which is a normal file) to check if I’m the only one modifying it. Fortunately, pyinotify comes to the rescue! Unfortunately, the documentation on their website is a little outdated. Something important to be noted is that pyinotify is based on a Linux Kernel feature called inotify; this means that it’s only available under Linux.

Anyway, after several tries and failures I manage to come up with a decent implementation of a watcher class. The example I’m about to provide uses ThreadedNotifier, since my watcher is supposed to allow my GUI application to run in parallel. Also, please note that you can’t monitor the file itself, but instead you need to monitor the changes to files in a directory! This part was somehow omitted from the documentation; I wonder why.
read more »

Writing Loadable Kernel Modules using netfilter hooks (in-depth HOWTO) – Part 1

Note: This article was inspired by the lack of updated documentation on how to write proper netfilter kernel modules. At the time I’m writing this article, the latest stable release was 2.6.32.8. I am also assuming you are familiar with how LKMs (Loadable Kernel Modules) work. If you are not, then you might want to check this article first: tldp.org/HOWTO/Module-HOWTO/

In this article (Part 1) I will present how to create a simple Linux kernel module that implements a netfilter hook for a generic transport protocol (not one of the usual ones).

In Part 2, I plan to connect the module to the iptables rules generated on the userspace side.
read more »