Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
Network Interface Finder - Java Code Bank
Network Interface Finder
Displays all the network interfaces a computer has in a GUI window.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import java.io.*;
import java.nio.*;
public class GuiIPAddress extends JFrame implements ActionListener
{
JButton btnDisplay;
JTextArea textResult;
public static void main(String args[])
{
JFrame f = new GuiIPAddress();
f.setTitle("Network Interface Viewer");
f.setSize(400, 550);
f.setVisible(true);
f.setResizable(false);
}
GuiIPAddress()
{
Container contentPane;
contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
textResult = new JTextArea();
textResult.setColumns(30);
textResult.setRows(30);
textResult.setEditable(false);
JScrollPane scrollText = new JScrollPane(textResult);
scrollText.setSize(200, 135);
scrollText.setBorder(BorderFactory.createLineBorder(Color.black));
contentPane.add(scrollText);
btnDisplay = new JButton("List all Network Interfaces");
contentPane.add(btnDisplay);
btnDisplay.addActionListener(this);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent event)
{
try {
Enumeration en = NetworkInterface.getNetworkInterfaces();
while(en.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface) en.nextElement();
textResult.append("\nNet interface:\n "+ni.getName());
Enumeration en2 = ni.getInetAddresses();
while (en2.hasMoreElements()){
InetAddress ip = (InetAddress) en2.nextElement();
textResult.append("\nIP address:\n "+ ip.toString());
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Comments
Sorry but there are no comments to display