Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

2007/08/16

pyScreenSpy, a Python implementation using Java libraries & JPython

I love Python, I dislike Java. But Java is maintained by a large corporation and has some tools that Python does not. It is possible to write a program in Python, using Python's core library and Java's library in the same program and compile it in a Java bytecode executable. All you need is to download and setup JPython. Here are the implications of developing a program using JPython:

Advantages:

  • Use both Java's and Python's libraries seamlessly in the same program.
  • Will work on all platforms that Java works.
Disadvantages:
  • Java's virtual machine is long to load (~3sec compared to Python's ~0.1 sec)
  • Some functionalities of Java and of Python are not available in JYthon, and the documentation about that is not very good.
As an example, I re-coded parts of the JScreenSpy application that I published a few days ago using JPython in 21 lines. This is just an example, I will re-release a fully working and ameliorated version (1.1) of JScreenSpy in Python in the following days.

Here is the source file, you can execute it using jpython pyScreenSpy.py
#Pythons imports
import os

#Java Imports
from javax import imageio
from java import awt
from java.awt import image
from java import io

#Determine current screen size
toolkit = awt.Toolkit.getDefaultToolkit();
screenSize = toolkit.getScreenSize();
screenRect = awt.Rectangle(screenSize);

#Create screenshot
robot = awt.Robot();

#Take ScreenShot
image = robot.createScreenCapture(screenRect);
imageio.ImageIO.write(image, "jpg", io.File("test.jpg") );
21 lines, in Python, using Java's libraries. How cool is that? Very!

2007/08/09

ScreenSpy: Record what your Computer is Doing while you are Away

I recently wrote a small program in Java that takes a screenshot every second or so and sends it to a FTP of your choice. It could be used to check which websites you children are visiting when you are away, or if they are approached by inappropriate individuals on myspace. I didn't make it stealthy, the goal is to give an incentive to your youngsters not to visit prohibited websites, not to catch them being naughty.

You can download it here:
ScreenSpy v1.0 (Win, Unix, MacOS) -- Includes source code.

Usage:

java -jar ScreenSpy.jar ftp.domain.com username password

or, for the win32 .exe:

Screenspy.exe ftp.domain.com username password
It will run on all major platforms give you have a java virtual machine installed (www.java.com). I also included a win32 binary.

Have fun!

By the way, I am looking for others fellow bloggers to contribute to this blog or to contribute to the source code of my projects. Leave a comment if interested.

*Q&A*

Matt:
If the screen has been idle, does it save space not hold off sending anything?

A:
Unfortunately not. It is a feature that could be added. Anyone has a good idea on how to implement that in Java? Save checksums of the pictures and compare them? If lots of people feel strongly about this I might try to find a solution...