Skip to content

Commit

Permalink
add switch network interface
Browse files Browse the repository at this point in the history
  • Loading branch information
argorar committed Jun 9, 2017
1 parent f630bea commit e06690b
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 34 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="lib"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="/home/sebastian/git_projects/Network-Watcher/lib/commons-net-3.6.jar"/>
<classpathentry kind="output" path="bin"/>
Expand Down
1 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/commons-net-3.6.jar
/co/
Binary file modified bin/co/edu/watcher/gui/WatcherGUI$1.class
Binary file not shown.
Binary file modified bin/co/edu/watcher/gui/WatcherGUI$2.class
Binary file not shown.
Binary file modified bin/co/edu/watcher/gui/WatcherGUI$3.class
Binary file not shown.
Binary file modified bin/co/edu/watcher/gui/WatcherGUI$4.class
Binary file not shown.
Binary file modified bin/co/edu/watcher/gui/WatcherGUI$5.class
Binary file not shown.
Binary file modified bin/co/edu/watcher/gui/WatcherGUI$6.class
Binary file not shown.
Binary file modified bin/co/edu/watcher/gui/WatcherGUI.class
Binary file not shown.
Binary file added img/about.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/ni.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 45 additions & 34 deletions src/co/edu/watcher/gui/WatcherGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@

/**
* Class main GUI
*
* @author Sebastian A. 2017
*/
public class WatcherGUI extends JFrame implements Runnable {

/**
* Global variables
*/
private static final long serialVersionUID = 2301685011176900485L;
private static final long serialVersionUID = 2301685011176900485L;
private WatcherUtil util = new WatcherUtil();
private Thread thread = new Thread(this);
private JPanel contentPane;
Expand All @@ -43,7 +44,7 @@ public class WatcherGUI extends JFrame implements Runnable {
private JLabel lblip;
private DefaultTableModel model;
private boolean status = false;
private String[] columnNames = { "IP Address", "Device Name"};
private String[] columnNames = { "IP Address", "Device Name" };

/**
* Create the frame.
Expand Down Expand Up @@ -82,7 +83,16 @@ public void mousePressed(MouseEvent e) {
frame.setVisible(true);
}
});
mnArchivo.add(mntmAcercaDe);
mnArchivo.add(mntmAcercaDe);

JMenuItem mntmSwitchNi = new JMenuItem("Switch NI");
mntmSwitchNi.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
seletionNI(1);
}
});
mnArchivo.add(mntmSwitchNi);
mnArchivo.add(mntmSalir);

JMenu mnstart = new JMenu("Start");
Expand Down Expand Up @@ -117,25 +127,25 @@ public void mousePressed(MouseEvent arg0) {
mnViewPorts.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if(seletion()){
if (seletion()) {
String ipHost = (String) model.getValueAt(table.getSelectedRow(), 0);
PortGUI frame = new PortGUI(ipHost);
frame.setVisible(true);
}
}
});
menuBar.add(mnViewPorts);
JMenu mnViewServices = new JMenu("View Services");

JMenu mnViewServices = new JMenu("View Services");
mnViewServices.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if(seletion()){
if (seletion()) {
String ipHost = (String) model.getValueAt(table.getSelectedRow(), 0);
ServicesGUI frame = new ServicesGUI(ipHost);
frame.setVisible(true);
frame.setVisible(true);
}
}
}
});
menuBar.add(mnViewServices);
contentPane = new JPanel();
Expand All @@ -154,28 +164,31 @@ public void mousePressed(MouseEvent e) {

panel_main = new JPanel();
contentPane.add(panel_main, BorderLayout.CENTER);
createTable();
seletionNI();
createTable();
seletionNI(0);
thread.start();

}



private void seletionNI() {
/**
* Method that show all network interface
* @param call : Kind of execution , 0 is the beginning
*/
private void seletionNI(int call) {
ArrayList<String> stockList = util.networkInterfaces();
String[] stockArr = new String[stockList.size()];
stockArr = stockList.toArray(stockArr);
stockArr = stockList.toArray(stockArr);
ImageIcon icon = new ImageIcon("img/network.png");
String resp = (String) JOptionPane.showInputDialog(null, "Please select a network interface.", "Network Interfaces", JOptionPane.DEFAULT_OPTION, icon, stockArr, stockArr[0]);
if(resp==null)
System.exit(ABORT);
String[] array=resp.split("/");
util.setPrivateIP(array[1]);
String resp = (String) JOptionPane.showInputDialog(null, "Please select a network interface.",
"Network Interfaces", JOptionPane.CLOSED_OPTION, icon, stockArr, stockArr[0]);
if (resp == null && call == 0)
System.exit(ABORT);
if (resp != null) {
String[] array = resp.split("/");
util.setPrivateIP(array[1]);
}
}



/**
* Methos that create the table
*/
Expand All @@ -199,20 +212,18 @@ public boolean isCellEditable(int row, int col) {
// Agregamos el scrollpanel al contenedor
panel_main.add(scrollpane, BorderLayout.CENTER);
}



/**
* Thread that does the scan
*/
public void run() {
while (true) {
try {
String[] list=util.getAddressList();
for (int i =0; i < list.length && state() == true; i++) {
lblscan.setText("Scanning :");
String[] list = util.getAddressList();
for (int i = 0; i < list.length && state() == true; i++) {
lblscan.setText("Scanning :");
lblip.setText(list[i]);
Object[] row = util.scan(list[i],false);
Object[] row = util.scan(list[i], false);
if (row != null)
model.addRow(row);
}
Expand All @@ -224,18 +235,18 @@ public void run() {
}
}
}

/**
* Method that verifies the selection of a host
* Method that verifies the selection of a host
*
* @return If there is a selection true, false in other case
*/
private boolean seletion() {
int s = table.getSelectedRow();
if (s==-1){
JOptionPane.showMessageDialog(null, "Please select a Host");
if (s == -1) {
JOptionPane.showMessageDialog(null, "Please select a Host", "Alert", JOptionPane.WARNING_MESSAGE);
return false;
}
else
} else
return true;
}

Expand Down

0 comments on commit e06690b

Please sign in to comment.