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