iptables throughput on Soekris net4801

Earlier today I had to find out what the capacity of a soekris net4801 running openwrt.

Using a fairly normal rule set, it can forward 51.8 Mbits/sec which is alright for a 266 MHz processor.

Sadly for me, we’ll be getting a 100 Mbit fiber optic connection at work in a few months, so I guess I’ll have to move to a net5501 unit in order to max out the connection.

Continue reading

Building postgresql8x and psycopg2 for x86_64 and i386 on Snow Leopard (OS X 10.6)

I’ve recently installed Apple’s new 64 bit OS Snow Leopard, on my work computer. I use postgresql extensivly together with python, and usually use apple’s bundled python2.5 for working with django.

As the daredevil I am, I wanted to recompile all my macports to use the new 64 bit system, and therefore deleted them all, and made a fresh install of macports. After building the postgresql81 port, I was about to build the psycopg2 python postgresql driver for python 2.5, when it gave me a warning about not being able to find some symbols in the postgresql library it had linked to. I quickly realized that this might be an architecture problem, and sure enough, it turns out that python 2.5 is a i386/ppc and python 2.6 is x86_64/i386/ppc binary, as can be seen here:

Continue reading

Python http_head method

Seeing as there is no really easy way to do a HTTP HEAD request from python, I wrote up the following small method:

In advance I’d like to apologize for the method that assemblies the request path.

Update: Added handling of redirects.

def http_head(url):
    import httplib
    import urlparse
 
    redirects = 0
 
    while redirects < 10:
        scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
 
        if scheme == 'https':
            conn = httplib.HTTPSConnection(netloc)
        else:
            conn = httplib.HTTPConnection(netloc)
 
        conn.request("HEAD", "%s%s%s%s%s" % (path, query and "?" or "", query,
                                             fragment and "#" or "", fragment))
 
        res = conn.getresponse()
 
        if res.status in (301, 302) and res.getheader('location'):
            url = res.getheader('location')
            redirects += 1
        else:
            break
 
    return res.status, res.reason

Very simple email sending method in python

I needed to send an email, so I came up with this:

 
def send_plain_mail(subject, body, from_mail, to):
    import smtplib
    from email.MIMEText import MIMEText
    from email.Encoders import encode_quopri
 
    msg = MIMEText(body, 'plain', 'iso-8859-1')
 
    msg['Subject'] = subject
    msg['From'] = from_mail
    msg['To'] = to
 
    s = smtplib.SMTP()
    s.connect()
    s.sendmail(from_mail, [to], msg.as_string())
    s.close()

Not rocket science, but it gets the job done.