A kid flying a kite.
Picture taken 2 years ago in Düsseldorf, on the Rhine promenade, during a sunny day.
How to query HTTP:BL for spamming IP addresses
1 Comment Published April 18th, 2012 in Internet, Java, Software, WebIf 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;
import java.net.InetAddress;
import java.net.UnknownHostException;
// see: http://www.projecthoneypot.org/httpbl_api.php
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 http://www.projecthoneypot.org/httpbl_configure.php
String accessKey = "abcdefghijkl";
String domain = "dnsbl.httpbl.org";
String lookup = accessKey + "." + reversed + "." + domain;
out.println("Lookup for: "+ lookup);
try {
String addr = InetAddress.getByName(lookup).getHostAddress();
translate(addr);
} 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");
System.exit(1);
}
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");
break;
case 1:
out.println("Suspicious");
break;
case 2:
out.println("Harvester");
break;
case 3:
out.println("Suspicious & Harvester");
break;
case 4:
out.println("Comment Spammer");
break;
case 5:
out.println("Suspicious & Comment Spammer");
break;
case 6:
out.println("Harvester & Comment Spammer");
break;
case 7:
out.println("Suspicious & Harvester & Comment Spammer");
break;
default:
out.println("Unknown");
break;
}
}
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 (91.207.8.78):
Querying HTTP:BL for IP: 91.207.8.78 Lookup for: abcdefghijkl.78.8.207.91.dnsbl.httpbl.org Response Code: 127.1.61.5 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.
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.
Ingredients:
- a jar
- a bash script
Let’s start with the jar. Create an HelloWorld.java 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 HelloWorld.java $ 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 “stub.sh”
#!/bin/sh java -jar $0 $* exit
Now let’s put together our self-executable java program:
$ cat stub.sh hello.jar > hello.sh $ chmod +x hello.sh
And now we can run it!
$ ./hello.sh 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.
Update:
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 exit
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.
OSX, Internet Sharing interfere with the standby sleep on MacBook Pro
1 Comment Published April 16th, 2012 in Apple, Errors, Hardware, Internet, Opinions, OSX, SoftwareYesterday 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.
The Azure Window, in Gozo Island, Malta
0 Comments Published January 8th, 2012 in Life, universe and everything
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.
Java Life (Code Hard) rap music video
0 Comments Published December 6th, 2011 in Java, Life, universe and everythingAnother funny video I found around.
I very much prefer this approach:
OutputStream out = new MyOutputStream(...); //may throw IOException
try {
//use the stream
} finally {
out.close();
}
than this:
OutputStream out = null;
try {
out = new MyOutputStream(...); //may throw IOException
//use the stream
} finally {
if (out != null) {
out.close();
}
}
I just find the first example correct and the second incorrect. I see the second ‘pattern’ everywhere.
Opinions?
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.
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.
Superdrive not working anymore
9 Comments Published August 25th, 2011 in Apple, Errors, Hardware, OSXAfter 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.
Search
About

"Thoughts about technology, code, life and diverse and occasionally related matters"
A blog by Luigi R. Viggiano
Archives
Categories
- Android (3)
- Apple (27)
- Books (7)
- Eclipse (14)
- Errors (4)
- Firefox (7)
- Git (2)
- Hardware (17)
- Horror Code (8)
- Internet (21)
- Java (102)
- JavaScript (9)
- Life, universe and everything (46)
- Lifehacks (25)
- Linux (51)
- Opinions (26)
- OSX (6)
- Python (1)
- Software (31)
- Speeches and Conferences (8)
- Unix (4)
- Web (23)
- Windows (19)
Tag Cloud
Android apple architecture Bash configuration CSS Development Düsseldorf Eclipse Git Google Hardware hdr How-To Java JAXB job junit Karmic Linux lion MacBook music Open Source Opinion oracle OSX patterns Pitfalls Practices Resume Security Software Suspend TDD Testing tip tonemapped Tricks Ubuntu unix video Web Workaround XML
WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.
Blog License
Blogs I like
Books on the desk
Friends' Blogs
- Antonio Terreno & Valter Bernardini
- Bruno Bossola
- Daniele Galluccio
- Domenico Ventura
- Ed Schepis
- Fabrizio Gianneschi
- Luca Grulla
- Luigi Zanderighi
- Marcello Teodori
- Mida Boghetich
- Muralidharan Chandrasekaran
- Piero Ricca
- Renzo Borgatti
- Simone Bordet
- Simone Bruno
- Uberto Barbini
- Valvolog
- Webtide blogs (Greg Wilkins & Jan Bartel)
Links























