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