1
19
20 package com.liferay.portlet.network.util;
21
22 import com.liferay.portal.kernel.util.StringUtil;
23 import com.liferay.portal.kernel.util.Time;
24 import com.liferay.portal.kernel.webcache.WebCacheException;
25 import com.liferay.portal.kernel.webcache.WebCacheItem;
26 import com.liferay.portlet.network.model.Whois;
27
28 import java.io.BufferedReader;
29 import java.io.InputStreamReader;
30 import java.io.PrintStream;
31
32 import java.net.Socket;
33
34
40 public class WhoisWebCacheItem implements WebCacheItem {
41
42 public static String WHOIS_SERVER = "whois.geektools.com";
43
44 public static int WHOIS_SERVER_PORT = 43;
45
46 public WhoisWebCacheItem(String domain) {
47 _domain = domain;
48 }
49
50 public Object convert(String key) throws WebCacheException {
51 Whois whois = null;
52
53 try {
54 Socket socket = new Socket(WHOIS_SERVER, WHOIS_SERVER_PORT);
55
56 BufferedReader br = new BufferedReader(
57 new InputStreamReader(socket.getInputStream()));
58
59 PrintStream out = new PrintStream(socket.getOutputStream());
60
61 out.println(_domain);
62
63 StringBuilder sb = new StringBuilder();
64 String line = null;
65
66 while ((line = br.readLine()) != null) {
67 if (line.startsWith("Results ")) {
68 break;
69 }
70
71 sb.append(line).append("\n");
72 }
73
74 br.close();
75 socket.close();
76
77 whois = new Whois(
78 _domain,
79 StringUtil.replace(sb.toString().trim(), "\n\n", "\n"));
80 }
81 catch (Exception e) {
82 throw new WebCacheException(_domain + " " + e.toString());
83 }
84
85 return whois;
86 }
87
88 public long getRefreshTime() {
89 return _REFRESH_TIME;
90 }
91
92 private static final long _REFRESH_TIME = Time.DAY;
93
94 private String _domain;
95
96 }