public void whois(HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("whois");
String domain = ServletRequestUtils.getRequiredStringParameter(request, "domain");
List<String> result = DomainUtils.whois(domain);
response.setContentType("text/plain");
response.setCharacterEncoding("utf-8");
PrintWriter writer = response.getWriter();
for (String s : result) {
writer.print(s);
writer.print("<br/>");
}
}
public class DomainUtils {
private static final Log log = LogFactory.getLog(DomainUtils.class);
/**
* 查询域名的whois信息
*
* @param domain
*/
public static List<String> whois(String domain) {
try {
Process p = Runtime.getRuntime().exec("whois " + domain); //执行linux whois 命令
ArrayList<String> buf = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
buf.add(line);
}
reader.close();
p.waitFor();
return buf;
} catch (IOException e) {
log.error(e);
} catch (InterruptedException e) {
log.error(e);
}
return null;
}
}