/* * @(#)Whois.java 1.0 01/04/2002 * * Copyright (c) 2002 Wapped Net, Ltd. All Rights Reserved. * * Wapped Net Ltd grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) Licensee does not utilize the software in a manner * which is disparaging to Wapped Net Ltd. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL WAPPED NET OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF WAPPED NET HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. */ import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; import java.net.*; import java.io.*; import javax.swing.border.*; public class Whois extends JApplet implements ActionListener{ // Host name of the whois server, and port. public final static String DEFAULT_HOSTNAME = "whois.internic.net"; public final static int DEFAULT_PORT = 43; boolean isStandalone = false; String hostname; int port; // Top level container JPanel whoisPanel = new JPanel(); // Contains two scroll panes. One button and a text field etc. // Holds the domain name to search for. JTextField searchString = new JTextField(); JLabel whoisLabel = new JLabel(); JButton findButton = new JButton(); // Output search results scroll pane JScrollPane stdScroll = new JScrollPane(); JTextArea errorOut = new JTextArea(); // Output system errors and warnings scroll pane. JTextArea stdOut = new JTextArea(); JScrollPane errorScroll = new JScrollPane(); TitledBorder titledBorder1; // Construct the applet public Whois() { } //Initialize the applet public void init() { String value; // SERVER HOSTNAME value = this.getParameter("hostname"); if( value == null ){ hostname = DEFAULT_HOSTNAME; } else{ hostname = value; } // PORT NUMBER value = this.getParameter("port"); if( value == null ){ port = DEFAULT_PORT; } else{ port = Integer.parseInt(value); } try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { titledBorder1 = new TitledBorder(""); this.setSize(new Dimension(290, 157)); searchString.setMinimumSize(new Dimension(30, 21)); searchString.setPreferredSize(new Dimension(200, 21)); searchString.setToolTipText("Enter the domain name to search for."); searchString.addActionListener(this); searchString.setActionCommand("find"); searchString.addActionListener(this); whoisLabel.setFont(new java.awt.Font("SansSerif", 1, 12)); whoisLabel.setForeground(Color.white); whoisLabel.setText("whois"); findButton.setText("find"); findButton.addActionListener(this); findButton.setBackground(Color.red); findButton.setFont(new java.awt.Font("SansSerif", 1, 12)); findButton.setForeground(Color.white); findButton.setBorder(BorderFactory.createRaisedBevelBorder()); findButton.setToolTipText("Select to find the domain name."); findButton.setActionCommand("find"); stdScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); stdScroll.setPreferredSize(new Dimension(20, 80)); stdOut.setToolTipText("Search results."); stdOut.setBackground(Color.pink); stdOut.setForeground(Color.white); stdOut.setFont(new java.awt.Font("SansSerif", 1, 9)); whoisPanel.setBorder(BorderFactory.createEtchedBorder()); errorScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); errorScroll.setPreferredSize(new Dimension(20, 40)); errorOut.setToolTipText("System errors and warnings."); errorOut.setBackground(Color.black); errorOut.setForeground(Color.green); errorOut.setFont(new java.awt.Font("Monospaced", 0, 9)); this.getContentPane().add(whoisPanel, BorderLayout.NORTH); whoisPanel.add(whoisLabel, null); whoisPanel.add(searchString, null); whoisPanel.add(findButton, null); this.getContentPane().add(errorScroll, BorderLayout.SOUTH); errorScroll.getViewport().add(errorOut, null); this.getContentPane().add(stdScroll, BorderLayout.CENTER); stdScroll.getViewport().add(stdOut, null); } //Get Applet information public String getAppletInfo() { return "Title: Whois\nAuthor:Wapped Internet Ltd \nWhois search engine."; } //Get parameter info public String[][] getParameterInfo() { String pinfo[][] = { {"hostname", "whois.internic.net", "Name of the whois server."}, {"port", "43", "Whois server port number."}, }; return pinfo; } // static initializer for setting look & feel static { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) {} } // What action event has been triggered? public void actionPerformed(ActionEvent e){ // Retrieve the action label associated with the object String cmd = e.getActionCommand(); // FIND BUTTON ACTIVATED or CARRIAGE // RETURN IN SEARCH STRING WINDOW if( cmd.equals("find" )){ lookUpName(searchString.getText() ); } } // End action. // Connect to the whois server and request information // for the domain name. public void lookUpName(String name){ Socket theSocket; BufferedReader theWhoisBuffer; PrintStream ps; String s; try{ theSocket = new Socket(hostname, port); ps = new PrintStream(theSocket.getOutputStream()); theWhoisBuffer = new BufferedReader(new InputStreamReader( theSocket.getInputStream())); ps.print(name + "\r\n"); while(( s = theWhoisBuffer.readLine()) != null){ stdOut.append(s + "\n"); } // End while. } catch( IOException e){ // Send the error out to the GUI text pane. errorOut.append(e.toString() + "\n" ); } } // End lookUpName }