Android Twisted SpyCam

I have been playing around with Androids ASE(android scripting environment). ASE allows you to run scripts on your android powered device. You can use Python, PHP, Javascript, Pearl, Ruby and much more. To install ASE on your device you must either have root, allow third party apps install,, or know how to sideload apk’s using android’s SDK tools like adb.

You can find the apk along with install instructions and more info on ASE at their website.

Here is an example of using python as a remote spycam. I am using the Twisted Framework as the server, and it gets interesting because I embed the captured image from the phone as base64 data on the webpage Twisted is serving up. You can choose to install the Twisted libs when you install python on your device. This is a fairly new feature.

To learn more about twisted, you can visit their website.

import android, os, base64
from twisted.internet import protocol, reactor

droid = android.Android()
os.chdir('/sdcard/webserver/')

def imgb64():
  droid.cameraCapturePicture('/sdcard/webserver/latest.jpg', True)
  im = open("latest.jpg","rb")
  ime = base64.b64encode(im.read())
  im.close()
  os.remove("latest.jpg")
  return ime

class ServeImage(protocol.Protocol):
  def connectionMade(self):
    data = imgb64()
    self.transport.write("""<html><head><title>Android Camera</title></head><body><img src="data:image/jpg;base64,%s" alt="image"/>test</body></html>""" % data)
    self.transport.loseConnection()

class ServeImageFactory(protocol.ServerFactory):
  protocol = ServeImage

reactor.listenTCP(8080, ServeImageFactory())
reactor.run()
Advertisements

About Tech B.

I am currently employed as a tech support rep for Frontier DSL internet and Dail-Up service. If you live on the East Coast and have Frontier or the old Verizon, you may have spoken with me at one point. I do side jobs programming and building things for people. I know Python better than any language in my toolbox. I can also develop Android Apps, which are Java based. Other languages include C , VB/VB.NET, some C#, PBASIC, Batch, Javascript, and some PHP. I love microcontrollers and interfacing with the outside world. I am currently working with Arduinos, which are amazing. Also I can work with the Basic Stamp family of microcontrollers; future development includes FPGA and embedded Linux. I was going to school, but have financial issues at the moment that are keeping me from the books. I plan on going back in the next couple semesters and finishing up my Associates in IT, then perusing a BS in computer science.
This entry was posted in Uncategorized and tagged , , , , , , , , , , , , , . Bookmark the permalink.

5 Responses to Android Twisted SpyCam

  1. joel says:

    your cool man, i think its java code right? I’m newbie in sl4a, is the programming support an intellisense? is it okay if you can sent me the .apk’s i cant find apk for java language to use in sl4a, engr_larion@yahoo.com.ph thank you.

    • Tech B. says:

      It is in Python not Java. SL4A is a scripting layer to the android OS. You can use a lot of scripting languages such as Lua, PHP, and Python.

      Android apps are developed in Java. You need to look into the Android SDK and develop native apps if Java is your language of choice.

    • evo says:

      Seriously Why did u say it is Java?

  2. g33ktricks says:

    I was reading your “About Me” and got quite imperresed. The way you have learned things without going to school.
    Thanks K.B for sharing the code.

  3. Hi Tech B, How can I call this server from another device?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s