NukeAll – for OSX

nukeall finds and removes (recursevely) the specified file(s) in the current folder.
Example:
nukeall .DS_Store
nukeall *.tmp
nukeall .*

You can also pass the -trashes option which will search and empty. Trashes folders which is useful on file servers.

Version 1.0 can be downloaded by clicking here

Check Apple RAIDs and email when there is a problem

This script can be used in a cron which runs every 5 or 10 minutes and will email as soon as it detects an issue with an Apple RAID.
I am working on an Apple XServe RAID checker, but this one will handle internal drive bay RAIDs.

#!/usr/bin/env python

import os
import string
import smtplib

from socket import gethostname

smtpserver = 'localhost'
smtpfrom = gethostname() + '@localhost'
smtpto = ['##EMAIL_OF_RECIPIENT##']

raidstatus = os.popen('/usr/sbin/diskutil listRaid')
status = raidstatus.read()
raidstatus.close()
if status.find('Degraded') > -1:
     smtpsubject = 'WARNING - Raid degraded on ' + gethostname()
     smtp = smtplib.SMTP(smtpserver)
     message = """\
From: %s
To: %s
Subject: %s

%s
""" % (smtpfrom, ", ".join(smtpto), smtpsubject, status)
     smtp.sendmail(smtpfrom, smtpto, message)
     smtp.quit()

Check OSX partitions and email results

I wrote a small Python script which gets a list of partitions and checks each one to make sure the partition is okay, and for the script to email the results.

#!/usr/bin/env python

import os
import string
import smtplib

from socket import gethostname

smtpserver = 'localhost'
smtpfrom = gethostname() + '@localhost'
smtpto = ['##recipient email##']

driveshandle = os.popen('/bin/df -h | grep disk')
drives = driveshandle.read()
driveshandle.close()
drives = drives.split('\n')

for drive in drives:

     diskinfo = ''
     if drive.find('dev') > -1:
          partition = drive.split(' ')
          print 'Drive ' +partition[0]
          fsck = os.popen('/sbin/fsck_hfs -fy ' + partition[0])
          diskinfo = fsck.read()
          fsck.close()
          smtpsubject = 'File System Checks for ' + gethostname() + ', drive ' + drive
          smtp = smtplib.SMTP(smtpserver)
          message = """\
From: %s
To: %s
Subject: %s

%s
""" % (smtpfrom, ", ".join(smtpto), smtpsubject, diskinfo)
          smtp.sendmail(smtpfrom, smtpto, message)
          smtp.quit()

print 'completed'

Blocking tor through iptables

I keep a database of tor hosts which gets updated quite often, and I have written a script in python which downloads the list and updates iptables so that they are all blocked.

It is recommended that the script gets added to cron so that the machines iptables keep up to date.

This script is ideal for schools and businesses to prevent people from circumventing content filtering, and also useful for servers to prevent abuse from ‘anonymous’ people who use tor for hacking for denial of service.

The script can be found here (http://www.andydixon.com/blocktor.py) and requires python (tested on v2.6)

Mass Python conversion

Over the coming months, all my backend code (eg non-web based code) is going to be migrated over to Python, this is both PHP and perl.

Provocateur is written in Python, and I am hoping to extend on this and combine many small code bases into one library and be able to control them from a central kernel, but this is my current flaw, and that is being able to work asynchronously without hanging the whole lot.

I think the above makes sense. In short, Provocateur kernel (with the IP communication code) works nicely, pass a job across to another part and it works, but the keep-alive does not get sent back in the kernel, so the communication gets dropped, but when dealing with waiting for the system to return a response, there is no chance of having a keep-alive call every once in a while, unless I am missing something..