-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpamCheck.java
More file actions
32 lines (28 loc) · 846 Bytes
/
SpamCheck.java
File metadata and controls
32 lines (28 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.net.*;
public class SpamCheck {
public static final String BLACKHOLE = "sbl.spamhaus.org";
public static void main(String[] args) throws UnknownHostException {
for (String arg: args) {
if (isSpammer(arg)) {
System.out.println(arg + " is a known spammer.");
} else {
System.out.println(arg + " appears legitimate.");
}
}
}
private static boolean isSpammer(String arg) {
try {
InetAddress address = InetAddress.getByName(arg);
byte[] quad = address.getAddress();
String query = BLACKHOLE;
for (byte octet : quad) {
int unsignedByte = octet < 0 ? octet + 256 : octet;
query = unsignedByte + "." + query;
}
InetAddress.getByName(query);
return true;
} catch (UnknownHostException e) {
return false;
}
}
}