-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path反垃圾邮件
29 lines (27 loc) · 860 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
import java.net.InetAddress;
import java.net.UnknownHostException;
public class Main {
public static final String blackhole = "sbl.spamhaus.org";
public static void main(String[] args) {
if(isSpammer(args[0])) {
System.out.println("suspected spammer");
} else {
System.out.println("reliable user");
}
}
private static boolean isSpammer(String s) {
try {
InetAddress ip = InetAddress.getByName(s);
byte[] b = ip.getAddress();
String addr = blackhole;
for(byte item : b) {
int block = item < 0 ? item + 256 : item;
addr = block + "." + addr;
}
InetAddress.getByName(addr);
return true;
} catch(UnknownHostException e) {
return false;
}
}
}