Hello there, im doing a small program just like a packet sniffer but i have a one problem.Below are the codes which are used to list all the network interfaces and the output will be something like this:
1.Interface Name's: lo / MS TCP Loopback interface
Address: 127.0.0.1
2.Interface Name's: eth0 / Realtek RTL8139 Family PCI Fast Ethernet NIC - Packet Scheduler Miniport
3.Interface Name's: eth1 / Gigabyte WIKG mini PCI WLAN Card - Packet Scheduler Miniport
Address: 192.168.1.101
4.Interface Name's: eth2 / Bluetooth Device (Personal Area Network)
then i created a dialog where a user can select one of the interface to be scan to do a packet analyser, but i don't know how the code will be.
I tried to search around and i came across the jpcap library,. i already tried to use it but it didnt work. i installed the jpcap and even use import jpcap.*; but it still got errors as if it doesnt recognise any syntax such as jpcap.JpcapCaptor or anything related to pcap.
please help me..if there are any alternative to do packet analyzer instead of using jpcap
Thank you
---------------------------------------------------------------------------------------
(codes use to list all the network interfaces)
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b1) {
if(true){
try{
java.net.SocketException se = new java.net.SocketException();
Enumeration enu = NetworkInterface.getNetworkInterfaces();
int i = 1;
while(i < 10 && enu.hasMoreElements()) {
NetworkInterface net = (NetworkInterface)enu.nextElement();
System.out.println(i+"." + "Interface Name's: " + net.getName() + " / " + net.getDisplayName() +"\n");
i++;
Enumeration enum2 = net.getInetAddresses();
while (enum2.hasMoreElements()) {
InetAddress address = (InetAddress)enum2.nextElement();
System.out.println("Address: " + address.getHostAddress()+ "\n");
}
}
JOptionPane.showInputDialog(null,"Select Interface to be scan", JOptionPane.QUESTION_MESSAGE);
// if(i == 1)///if a user select one of the interface, it will do packet analyzer
}
catch(java.net.SocketException se){
se.printStackTrace();
}
}
}