Monthly Archives: December 2009

How to sum the sizes of files found by ‘find’

Sometimes you want to find the size of all files that match some criteria, for example: files older than N days, or files greater than N bytes, or files that have a certain extension.

In this case, using du is not practical. Here is a simple awk one-liner that will sum the size of all files under /path that are older than 90 days:

find /path/ -type f -mtime +90 -printf "%s\n"|awk '{sum+=$0}END{print sum}'



Spoofing MAC address under MacOSX Snow Leopard


If you travel a lot like me, you may find yourself in need to change the mac address of your gizmos to avoid paying multiple times for the same service.
Many hotspot services (commonly found in hotels) require you to pay for an access code for each wireless device that you bring with you. Usually these hotspots ask you to pay to get your mac address “allowed” to connect to the Internet for 24 hours.
Just pay once and change the mac address of your other devices so that they are all the same, but avoid using them at the same time :) You may screw up the network :)

Changing the mac address is also useful when you find some open wireless network protected only by mac filtering. But that’s another story.

How to spoof MAC address on MacOSX

In the past it was kinda easy to spoof your mac address under MacOSX, both for wired and wireless interfaces.
Nowadays, you can no longer use a simple ifconfig en1 ether XX:XX:XX:XX:XX:XX. Things got a little more complicated for wireless interfaces.

The problem is that you cannot modify the mac address of a wireless interface which is associated to some network. Right, you may think, so let’s take the interface down, change the mac addy and bring the interface up again. No, that won’t work either: you cannot modify the mac address while the interface is down.

Welcome airport -z. This command will disassociate your Airport card from any wireless network and at the same time keep the interface up.

The path of this tool under MacOSX is: /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
You may want to symlink it to one of your $PATH dirs, like this:

sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport

Now run as root:

airport -z

Wait a few seconds, and change your mac address:

ifconfig en1 ether XX:XX:XX:XX:XX:XX

Wait a few seconds. Verify with ifconfig en1 that the mac address was actually changed and in case it has not, retry the ifconfig en1 ether XX:XX:XX:XX:XX:XX command again until ifconfig en1 shows the correct mac address. Like I said you should wait a few seconds between each command.

Then open your Airport utility and choose your wireless network.

Thumbs up :)