Archive Page 2

If you don’t know Project Honey Pot, go and have a look.

They offer a service for querying IP addresses and check if they are listed in those involving in spamming or threatening activities. So, if your visitor has a black listed IP you can block him from accessing or doing something sensitive.

Since it is missing a Java library to use the service, I implemented a Spike following the HTTP:BL API specifications.

This is not production code, is just some (ugly) code I wrote to test how it works.

import static java.lang.Integer.parseInt;
import static java.lang.System.out;


// see:
public class HttpBlackListChecker {

	public static void main(String[] args) throws Exception {
		if (args.length == 0) help();
		String ip = args[0]; 
		out.println("Querying HTTP:BL for IP: " + ip);
		String reversed = reversed(ip); 
		// get your own key at
		String accessKey = "abcdefghijkl";                     
		String domain = "";
		String lookup = accessKey + "." + reversed + "." + domain;
		out.println("Lookup for: "+ lookup);
	    try {
	    	String addr = InetAddress.getByName(lookup).getHostAddress();
		} catch (UnknownHostException e) {
			out.println("The IP specified is not listed in HTTP:BL");

	private static void help() {
		out.println("Please specify an ip address to check");

	private static void translate(String addr) {
		String[] split = split(addr);
		out.println("Response Code: " + addr);
		out.println("Result: " + (split[0].equals("127") ? "found" : "error"));
		out.println("Days since last activity: " + split[1]);
		out.println("Treat score (0..255): " + split[2]);
		out.print("Type of visitor: ");
		int type  = parseInt(split[3]);
		switch (type) {
		case 0:
			out.println("Search Engine");
		case 1:
		case 2:
		case 3:
			out.println("Suspicious & Harvester");
		case 4:
			out.println("Comment Spammer");
		case 5:
			out.println("Suspicious & Comment Spammer");
		case 6:
			out.println("Harvester & Comment Spammer");
		case 7:
			out.println("Suspicious & Harvester & Comment Spammer");

	private static String reversed(String ip) {
		String[] split = split(ip);
		String reversed = null;
		for (String chunk : split) 
			reversed = (reversed == null) ? 
						chunk : 
						chunk + "." + reversed;
		return reversed;

	private static String[] split(String ip) {
		return ip.split("\\.");

This code won’t work if you don’t request an API key from here and replace it at line #16.

Sample output specifying one spamming IP (

Querying HTTP:BL for IP:
Lookup for:
Response Code:
Result: found
Days since last activity: 1
Treat score (0..255): 61
Type of visitor: Suspicious & Comment Spammer

Notice that some ISP DNS server redirect to a “courtesy page” of the ISP itself, when you specify a non-existent host. In this case you’ll get some wrong repose code when the IP is not listed. You’ll see “Result: error” in the output, instead of “The IP specified is not listed in HTTP:BL”. The fault in this case if of your ISP.

Self executing jar files

I personally always felt bad about the fact that we have to provide a shell script which runs the executable jar file. It would be nice if we could provide a self contained executable in a single file, right?

I just discovered a trick which works on unix, but it can possibly be adapted on Windows.

– a jar
– a bash script

Let’s start with the jar. Create an file:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");

I like to indicate the Main Class in the manifest, so we create a MANIFEST.MF:

$ echo Main-Class: HelloWorld > MANIFEST.MF

now, let’s put the jar together:

$ javac
$ jar -cvmf MANIFEST.MF hello.jar HelloWorld.class 

You can try it:

$ java -jar hello.jar 

It should print “Hello World!”. No surprise.

Now, let’s create, once and for all, the bash script “”

java -jar $0 $*

Now let’s put together our self-executable java program:

$ cat hello.jar >
$ chmod +x

And now we can run it!

$ ./ 
Hello World!

Cool uh?

I think, you can create a stub.bat on Windows; possibly you should just replace the first line with “@echo off” and the “$0 $*” with “%0 %1 %2 %3 %4 %5…”. It should work. Don’t ask me to test the Windows version. I’m allergic.

A shorter version of the stub script:

#!/usr/bin/java -jar

For windows, this should translate to stub.bat:

@java -jar %0 %1 %2 %3 %4 %5

For windows, depending on what you use to concatenate files (copy /b should work) make sure there is a newline between the end of the stub.bat and the beginning of the jar file. I didn’t test on Windows, but I’m pretty sure it will work. Let me know, if otherwise.

Yesterday I noticed that when I close the lid of my MacBook Pro the light in front of the case was not indicating that the computer was going to sleep normally. Still the fans were running and when I opened the lid, I saw that it was not resuming from sleep properly, presenting a strange behavior: it asks for a password for a second or so, then the screen goes black again, and I need to turn it on manually pressing the light buttons (fn+F1/F2) then the screen appears again.

I debugged the problem and I discovered the cause.

The cause is that I enabled “Internet Sharing” from the “Sharing” item in the “System Preferences”. Basically I am sharing the WIFI internet to set of devices connected to the Ethernet.
If the WIFI is enabled (and connected) and the Internet Sharing is enabled, my MacBook hangs while doing the sleep process.

After resetting the SMC and trying several times to close all possible apps which may interfere, I finally found that the Internet Sharing is affecting this behavior.
Another workaround I found is to disable the WIFI. In this way the “Internet Sharing” is also disabled and the problem doesn’t happen anymore.

I reported the bug to Apple, and I hope they will have a look and try to solve it. To me, it is obviously a BUG in the Internet Sharing feature, which by the way it’s superb.

New year, new life. Got my camera bag stolen with all the gears in my hometown Turin. Yesterday I was looking back to the old pictures, and I found some good ones made with a 10 year old super compact camera, Pentax Optio S. I found this one and I like it. Unfortunately I lost also this camera too, during the misadventure in Turin.

Another funny video I found around.

I/O Exception handling

I very much prefer this approach:

OutputStream out = new MyOutputStream(...); //may throw IOException
try {
    //use the stream
} finally {

than this:

OutputStream out = null;
try {
    out = new MyOutputStream(...); //may throw IOException
    //use the stream
} finally {
    if (out != null) {

I just find the first example correct and the second incorrect. I see the second ‘pattern’ everywhere.


Sunset on Salzburg by Luigi R. Viggiano
Sunset on Salzburg, a photo by Luigi R. Viggiano on Flickr.

I got very positive comments about this picture I made yesterday evening in Salzburg. My only picture in flickr explore was another sunset I shot in Dusseldorf, and this one is getting good attention today, so I hope it will be my second flickr explore pic.
Some work colleagues suggested a bit of fill light at the base. I actually used some vignette effect to focus the viewer attention on the center; if the composition was a little bit better I could have cropped the base area a little bit more still keeping the sun and the mountains in the right position.
Still, it looks like everybody likes this shot. So here I share it also on my blog.

Venetian Mask

Venetian Mask by Luigi R. Viggiano
Venetian Mask, a photo by Luigi R. Viggiano on Flickr.

I made many pictures of those masks in Roman shops. In some shops I saw same sign saying "no picture please". Eventually the idea to shot those colorful masks is not too original, and the shop owners get tired of people coming in just for pictures. BTW those masks are for sure the most colorful subjects I found so far. And here’s another one.
The price for the most funny sign in a souvenir shop goes to the one with "for the sake of our health we don’t provide touristic informations!", wow :-)
In my ‘venetian masks’ set, this one above is definitely my favorite.

After installing OS X Lion I tried to burn a DVD in my macbook, and it turns out that this is what I get using Disk Utility:

I tried several DVDs (DVD+R, DVD-R, different brands, and tried to burn at different speed), with no luck. Also it refuses to read movie DVDs. But it can read the Snow Leopard DVD, so I hope that at least it can read common data DVDs.

I tried to reset the SMC and PRAM/NVRAM, no luck again.

Still remains to try some other burning software.

Reading support forums and searching on google has been a waste of time so far.
I don’t know if this is a side effect of Lion installation, or it is just a coincidence, but since now Apple didn’t ship any update. Only I find it quite suspicious that if you just search for “Lion superdrive” you find many people having problems with those two.

I used my DVD very few times, if it is an hardware problem it means that the claimed superior hardware quality of Apple is just another myth.

Big disappointment by Apple, either if it is a software or hardware problem. Super…drive.

Landscape Silhouette

This picture has been shot from the Rhein promenade in Düsseldorf. I remember I was having a bad day at home, so I went out for a photo walk, which extended to be till late evening. I come back with a lot of good shots. The sun was red and visible by bare eyes, and the buildings were completely black, projecting only their own shadow. At the time I didn’t know that this was a perfect subject for a ‘Silhouette‘ photography. I’m still a photo beginner.
This is my first picture on Flickr Explore. I increased the red a little bit, but this picture is almost a “straight out of the camera” one.


You are currently browsing the NewInstance weblog archives.


October 2017
« Nov    

Follow me

twitter flickr LinkedIn feed

Subscribe by email

Enter your email address:



Tag Cloud