Archive for December, 2009

How to find the IP/MAC addresses of devices on your network

December 28, 2009

Every once in a while I need to find out the IP & MAC addresses of various devices in my home network. Here is a small shell script that will find this information. It takes a while to run. Without the initial ping, the arp command will not return the necessary data on an IP address that you’ve never visited from the machine that you’re running this script on.

Perhaps there is a better way of finding the IP/MAC addresses of devices on your network. If so, please let me know.

#!/bin/sh

for (( i = 0; i < 256; i++))
do
    ping -c 1 10.0.1.$i
    arp 10.0.1.$i
done

“Adobe Unit Types.osax” & debugging Python on Mac

December 4, 2009

On OSX, if you’ve installed one of the Adobe apps, then when you debug your Python application you’ll start getting this annoying set of errors on the console:

osascript[13514:607] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
	/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

Here is how you get finally get rid of this problem. Delete this file alone wont fix the problem since launching another Adobe app will more than likely recreate this file. I found this solution to work:

cd /Library/ScriptingAdditions
sudo ln -s /dev/null ./Adobe\ Unit\ Types.osax

AuthKit, valid_password and wraptools

December 4, 2009

I’m new to AuthKit, and I wanted to override the method authkit.authenticate.valid_password for the form way of handling authentication. But could not figure out a good way of doing this. It appears that they only way overriding this method is to use the forward handler, but then again I had AuthKit working more or less the way I wanted using the form handler.

So how do you go about overriding one method in a library that you’re using? Well in Python you can use the wraptools module. This allows you to override a method using decorators. For example,

@replaces(authkit.authenticate.valid_password)
def valid_password(environ, username, password):
    try:
        # validate the username/password
        return True
    except YourLoginException:
        return False

Flup, AuthKit, & unicode strings

December 1, 2009

If you’re on a hosting environment (e.g., bluehost.com) where the only option to run Python/Pylons is via flup (fast cgi), then you may have experienced this error:


<'exceptions.AssertionError'>: write() argument must be string

The bottom line is that the WSGI spec only supports plain strings.

AuthKit, is a middleware that intercepts HTTP request/response in order to enforce authentication and authorization. One issue that you will encounter is that any page that gets rendered via AuthKit by default will be in unicode. This causes flup to throw the above exception. The fix is pretty straight forward:

def render_signin():
    result = render('/signin.mako')
    result = result.replace('%', '%%').replace('FORM_ACTION', '%s')
    return unicode(result).encode('utf8')

Simply cast the result to unicode and encode it to utf8.


Follow

Get every new post delivered to your Inbox.