May 19, 2010

I was playing around with Java again, and decided to attempt to create a GUI for my SubDomainer app. Here is the resulting code:

import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;
import java.util.*;

public class SubDomainerGUI extends JFrame implements ActionListener
{
DataOutputStream output;

JPanel firstRow = new JPanel();
JPanel secondRow = new JPanel();

JPanel fieldPanel = new JPanel();
JPanel buttonPanel = new JPanel();

JLabel targetLabel = new JLabel("Target URL: ");
JTextField targetURL = new JTextField(20);
JLabel reminderOne = new JLabel("Please enter the target URL without 'www.' attached.");

JButton scanButton = new JButton("Scan");
JButton exitButton = new JButton("Exit");

public static void main(String[] args)
{
SubDomainerGUI f = new SubDomainerGUI();
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
f.setSize(400,170);
f.setTitle("SubDomainer");
f.setResizable(false);
f.setLocation(200,200);
f.setVisible(true);
}

public SubDomainerGUI()
{
Container c = getContentPane();
c.setLayout((new BorderLayout()));
fieldPanel.setLayout(new GridLayout(4,2));
FlowLayout rowSetup = new FlowLayout(FlowLayout.CENTER);
firstRow.setLayout(rowSetup);
secondRow.setLayout(rowSetup);
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

firstRow.add(targetLabel);
firstRow.add(targetURL);

secondRow.add(reminderOne);

fieldPanel.add(firstRow);
fieldPanel.add(secondRow);

buttonPanel.add(scanButton);
buttonPanel.add(exitButton);

c.add(fieldPanel, BorderLayout.CENTER);
c.add(buttonPanel, BorderLayout.SOUTH);

scanButton.addActionListener(this);
exitButton.addActionListener(this);

try
{
output = new DataOutputStream(new FileOutputStream("SubDomainer_Results.txt"));
}

catch (IOException ex)
{
System.exit(1);
}

addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
int answer = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit?", "Exit", JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.YES_OPTION)
finish();
}
}
);
}

public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();

if (arg == "Scan")
{
try
{
String subdomains[] = {"access", "admin", "backup", "backup2", "beta", "cgi", "code", "customers", "database", "db", "dev", "download", "downloads", "email", "finance", "ftp", "gateway", "guest", "help", "helpdesk", "internal", "intranet", "kb", "login", "mail", "mailhost", "mailserver", "ns1", "ns2", "partners", "products", "proxy", "secret", "secure", "server", "test", "webmail", "www2", "www3"};
try
{
InetAddress ipaddress = InetAddress.getByName(targetURL.getText());
output.writeUTF("\n");
output.writeUTF("Scanning " + targetURL.getText() + " (" + ipaddress.getHostAddress() + ") \n");
output.writeUTF("-----------------------------------------------\n");
}
catch ( UnknownHostException e1)
{
JOptionPane.showMessageDialog(null,"ERROR: Host IP address cannot be resolved.", "Error in URL", JOptionPane.ERROR_MESSAGE);
finish();
}

for (int i = 0; i <>
{
String newhostname = subdomains[i] + "." + targetURL.getText();
try
{
InetAddress newipaddress = InetAddress.getByName(newhostname);
output.writeUTF("\n");
output.writeUTF(newhostname + " (" + newipaddress.getHostAddress() + ") EXISTS \n");
}
catch(UnknownHostException e2)
{
output.writeUTF("");
}
}


JOptionPane.showMessageDialog(null,"The scan results have been saved.","Scan Successful", JOptionPane.INFORMATION_MESSAGE);
}

catch(IOException ex)
{
System.exit(1);
}
finish();
}

else
{
try
{
output.close();
}
catch(IOException c)
{
System.exit(1);
}
finish();
}
}

public static void finish()
{
System.exit(0);
}
}

Subscribe to RSS Feed Follow me on Twitter!