Matthew Hutchinson

about

Matt is a web developer from N. Ireland. He currently runs Hiddenloop and works in Dublin. Want to find out just a little bit more ?

An audio feed is available for the latest articles at matthewhutchinson.net, find it here.

RBot

posted 10 months ago in , ,

I think IRC is a vastly under-rated tool. It is somthing I used a lot in the mid/late 90’s and in my first few years at University on the old DEC Workstations. Back before Skype and before the web was getting ready for its next version number, IRC was the best way to chat online.

For a long time I forgot about IRC, until it became obvious that (with a channel bot) it can be useful for all sorts of things, beyond just regular chat. With a bot parsing and watching RSS feeds, your channel can include notifications for just about anything you want, SVN commits, Trac tickets, even exceptions thrown from your code (you’ll have to build a feed for that yourself).

So I looked into setting up a channel bot myself (something I haven’t done before). Looking around I played with infobot (Perl) and eggdrop (C/TCL) – before (rather predicatably) going with RBot (Ruby) I had a little hassle getting the bot to work on Debian. It requires the Berkley Database (and Ruby’s binding to it).

Of course the BDB that comes with GNU/Debian Linux (apt-get) is out of date, and you will need to compile the most recent version instead. If you already installed Berkeley DB on your Debian Box, uninstall it to prevent conflicts. Then get it from here (./configure, make, make install). Choose BDB 4.4 or lower since the Ruby BDB bindings are not compatible with the new 4.5) – I couldn’t find all of those caveats documented together in the one place, so that may be of use to someone.

Next grab Ruby’s BDB bindings – and finally make sure you can call the bdb library in irb. If you can do,

1
2
3
:~$ irb
>> require 'bdb'
=> true

- without throwing an error, then download and install RBot. Its fairly simple to setup and there are a large number of plugins to play around with. Rbot will install a some of these by default (including rss.rb) and you can extend them, or write your own in the bot’s local plugin directory.

To persist the bot, use a simple ‘keep alive’ script;

#!/bin/bash

proc=`ps -fu $LOGNAME | grep name_of_your_bot | grep -v grep | wc -l`
if test $proc -eq 0
then
 nohup rbot /home/username/.name_of_your_bot > /dev/null &
fi

And put it in a cron job to check its running (e.g. every 55 minutes);

# make sure rbot is running all the time
*/55 * * * * /home/username/rbotchk.sh

My work in progress Rbot (kafka) is sitting in #komura on irc.perl.org – expect it to be broken most of time as I add a few plugins and try stuff out.

While there are hundreds of IRC clients available, I have stuck to using IRSSI (a terminal client) its old-fashioned (I know), but simple and I can access it from anywhere (keeping it running on a screen). I’d also recommend Colloquy a decent graphical client for OSX.

REST and Rails (1)

posted 10 months ago in , ,

Here are some links that may be of use to anyone getting started with REST Resources in Rails.

1 comment

Packet Capture with Ruby, pcaplet and libpcap

posted 10 months ago in , ,

Some years ago I made use of a Windows based (and free) packet analsyer tool Packetyzer, from Network Chemistry) It did the job and proved to be invaluable for testing and building different packet headers – for projects just like this – but as a fan of Ruby, I had to see if this could be done in the language of my choice.

Just a few months ago I began doing a little research into GPRS packets for a potential ‘location-based’ mobile web service. To do this I was hoping to use Ruby and through pCap I was able to.

To start monitoring packets, you’ll first have to install libpcap – a low level packet capture library (authored in C) – from LBNL’s Network Research Group You can follow this short tutorial to do this. The libpcap library grabs packets from any network adaptor on your system, giving you the raw data to work with. Doing this is immensely powerful, you could write listeners to monitor anything from email traffic to instant message conversations (provided the traffic isn’t encrypted of course).

Next, to allow us to write Ruby code to interface with this library, you’ll need to install pcaplet – This Ruby binding library makes writing capture programs easy. Its as simple as using require ‘pcaplet’ at the head of your Ruby code and your off.

I was able to use these libraries to examine TCP/IP packets from my mobile device (sent via GPRS over TCP/IP) to my server. The following Ruby script extracted the information I was interested in (data addressed to HTTP) using a regular expression;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env ruby

require 'pcaplet'

# create a sniffer that grabs the first 1500 bytes of each packet
$network = Pcaplet.new('-s 1500')

# create a filter that uses our query string and the sniffer we just made
$filter = Pcap::Filter.new('tcp and dst port 80', $network.capture)
$network.add_filter($filter)

# the packet sniffer loop
for p in $network
  # if the packet matches the filter and the regexp...
  if $filter =~ p and p.tcp_data =~ /GET(.*)HTTP.*/
    # print all packet data for each packet that matches
     puts p.tcp_data
  end
end

Then save this and run the script with something like;

ruby packet_filter_regex.rb 
# you may need to run this as root if you have permission problems

The add_filter function, with ‘tcp and dst port 80’ – means all tcp traffic directed at port 80 on the adapter, this resource details all the tcpdump syntax for different filter designs. This code will be a useful tool for me in another project -looking at streaming video and audio.

Another article at Linux.Ars roughly describes what is behind this and shows some more example Ruby scripts for packet monitoring (including an aim chat sniffer). There are also a few more example filters on the pcaplet site.

Apr-07 UPDATESylvain Sarmejeanne has just released Scruby a Ruby application that works on UNIX providing a shell where you can perform packet creation, sending and sniffing functions in a Ruby-esque fashion. It requires libpcap and uses PCapRub (a mininal PCAP wrapper) rather than using PCAP directly. The package is well documented and has an irb-like interface, accepting command line input for debugging.

Books and Feeds

posted 10 months ago in ,

Following on from Carisenda’s ‘book reading shame’, here is a list of what I got through in 2006. In 2005 I finished every Stephen Ambrose book he’d published and generally overdosed on WWII factual history a bit too much. Men of Valour is worth a read if you’re interested in getting introduced to that type of thing.

Last year I read into the history of programming, hackers and Apple a bit—and while visiting Japan I was introduced to Haruki Murakami, without a doubt the best fictional work I have read in years. His books remind me of stories you’d expect from a Studio Ghibli production.

(I know some people can read this many books in a couple of months, I tell myself, reading slowly, I’m getting more out of them …)

Anyone else got any books to recommend ?

update You can also take a look at what feeds I subscribe to and read on a semi-daily basis.

2006, a mini review (2)

posted 10 months ago in ,

I’ve actually blogged more in the last 12 months than I thought I would. So rather than rant on about how crazy a year this has been for me, (working for the BBC, moving to London, leaving Belfast, travelling to Japan) – here are a few nostalgic links from 2006;

Reflecting back, I am sure a lot more happened than this… Notable mention also goes to the closure of Raffles – which provided quality, affordable sandwiches to most of Belfast’s top web talent. And to Skribe a project which has struggled to get off the ground all year and now looks back on track for 2007.

2 comments