Android on IRC

I recently gave a lecture on DDoS in my Network OS class. I demonstrated a simple bot on the computers in the class. I also demonstrated how portable devices are capable of running bots as well.

I used Android Scripting Environment (ASE) for the demo. The commands I gave it where text, call, speak aloud, and vibrate. The only draw back ASE has is no real GUI support. I can’t wait for the day when OpenGL ES is ported to python. Anyway, ASE allows access to almost all of the phones featurtes. Here is a link to the API ref: http://code.google.com/p/android-scripting/wiki/ApiReference


#-------------------------------------------------------------------------------
# Name:        AndroidIRC
# Purpose:     Android based IRC bot
#
# Author:      K.B. Carte (techb)
#
# Created:     10/26/2010
#
# Copyright:   (c) K.B. Carte (techb) 2010
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import socket, string, time, os, sys, android
droid = android.Android()
os.chdir("sdcard")

droid.makeToast("AndroidBot Started")
droid.vibrate(300)

chan = 'AndroidBot'
ircsite = 'irc.freenode.net'
port = 6667

irc = socket.socket()
irc.connect((ircsite, port))
n = 'AndroidBotV1'
irc.send('NICK %s\r\n' %  n)
irc.send("USER %s %s bla :%s\r\n" % ("Ohlook", 'itsnotmy', 'Realname'))
time.sleep(4)
irc.send("JOIN #%s\r\n" % chan)

readbuffer = ''
while True:
    readbuffer= irc.recv(1024)
    temp=string.split(readbuffer, "\n")
    Check = readbuffer.split(':')
    print readbuffer

    if 'PING' in readbuffer:
        """PIN/PONG connection echo response"""
        irc.send("PONG :%s" % Check[1])

    if 'JOIN' in readbuffer:
        """Greet people that join the channel"""
        na = Check[1].split('!')
        irc.send("PRIVMSG #%s :Hello %s\r\n" % (chan, str(na[0])))

    if '^call' in readbuffer:
        number = readbuffer.split(':')
        droid.phoneCallNumber(number[3].strip())

    if '^text' in readbuffer:
        "texts the number 5 times with given message"
data = readbuffer.split(":")
        number = data[3].strip()
        message = data[4].strip()
        print number, message
        cnt = 0
        while cnt < 5:
            droid.smsSend(number, message)
            cnt += 1

    if '^vibe' in readbuffer:
        droid.vibrate(300)

    if '^say' in readbuffer:
        say = readbuffer.split(":")
        droid.ttsSpeak(say[3].strip()