Ethernet port in java

Ethernet port in java

Hello,
I am new to this field. I have to make an web application in JSP in which i have to decode the packets received on ethernet port. I have no idea how to program the ethernet port in java and read packets.

Please guide me..........
View Answers

December 14, 2010 at 11:24 AM

Use the following code that basically works on TCP/IP protocol suit. Hope it will help you :-)

    import java.net.*;

07 import java.io.*;

08 import jpcap.JpcapCaptor;

09 import jpcap.JpcapSender;

10 import jpcap.NetworkInterface;

11 import jpcap.NetworkInterfaceAddress;

12 import jpcap.packet.*;

13
14 class Main { 15

16 /* variables */

17 JpcapCaptor captor;

18 NetworkInterface[] list;

19 String str,info;

20 int x, choice; 21

22 public static void main(String args[]) {

23 new Main(); 24 } 25

26 public Main() { 27
28 /* first fetch available interfaces to listen on */

29 list = JpcapCaptor.getDeviceList();

30 System.out.println("Available interfaces: "); 31

32 for(x=0; x

33 System.out.println(x+" -> "+list[x].description);

34 } 35
System.out.println("-------------------------\n");

36 choice = Integer.parseInt(getInput("Choose interface (0,1..): "));

37 System.out.println("Listening on interface -> "+list[choice].description);

38 System.out.println("-------------------------\n"); 39

40
41
42 /*Setup device listener */

43 try { 44 captor=JpcapCaptor.openDevice(list[choice], 65535, false, 20);

45 /* listen for TCP/IP only */

46 captor.setFilter("ip and tcp", true);

47 }

48 catch(IOException ioe) { ioe.printStackTrace(); }

49
50
51 /* start listening for packets */

52 while (true) { 53
54 Packet info =captor.getPacket();

55 if(info != null) 56 System.out.print(getPacketText(info));

57 } 58 } 59
60
61 /* get user input */

62 public static String getInput(String q) {

63 String input = "";

64 System.out.print(q);

65 BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));

66 try {

67 input =bufferedreader.readLine();

68 }

69 catch(IOException ioexception) { }

70 return input;

71 } 72
73

74 /* return packet data in true text */

75 String getPacketText(Packet pack){

76 int i=0,j=0;

77 byte[] bytes=new byte[pack.header.length + pack.data.length];

78

79 System.arraycopy(pack.header, 0, bytes, 0, pack.header.length);

80 System.arraycopy(pack.data, 0, bytes, pack.header.length, pack.data.length);

81 StringBuffer buffer = new StringBuffer();

82
83 for(i=0; i

84 for(j=0;j<8 && i

85 String d = Integer.toHexString((int)(bytes [i] &0xff));

86 buffer.append((d.length() == 1 ? "0" + d:d ) + " "); 87

88 if(bytes[i]<32 || bytes[i]>126)

89 bytes[i] = 46; 90 }

91 }

92 return new String(bytes,i - j, j);

93 } 94 }


April 14, 2011 at 9:46 PM

Can you please post the complete code....it's incomplete at line number 32...









Related Tutorials/Questions & Answers:
Ethernet port in java - Java Beginners
Ethernet port in java  Hello, I am new to this field. I have to make an web application in JSP in which i have to decode the packets received on ethernet port. I have no idea how to program the ethernet port in java and read
Setting source port on a Java Socket?
Setting source port on a Java Socket?  Is it possible to explicitly set the the source port on a Java Socket
Advertisements
server with two port - Java Server Faces Questions
server with two port  Hello, want to write two port server socket program using Java, (i.e. single server program which is listening on two ports... respectively. If C1 send object to the server (using the connection to 3122 port
Overview of Networking through JAVA,Getting the Local port
:\roseindia>java LocalPort There is a server on port 135. There is a server... Getting the Local port     ... port. Here we are going to make it easier to understand the step be step
listening http port 8080 - Java Server Faces Questions
listening http port 8080  Hi Sir I just need java code through which i can listen the http port 8080 ... i want to interpret the http request before it reaches the server and i also want to know how to send it back
send data thru parallel port - Java Beginners
send data thru parallel port  Hi, I want to print send data to printer thru parallel port.How can it be possible thru java code
Listening port 8080
Listening port 8080  I need a java code through which i can listen the http port 8080 ... i want to interpret the incoming http request on 8080 port. Please help
java - Java Beginners
java  hi i want code in java language to read data from ethernet port
port number - JavaMail
port number  i want james2.1.3 port number like microsoft telnet>open local host _______(some port number) i wnat that port number
Changing MySQL Port Number
Changing MySQL Port Number  How to change the MySQL port... installation directory. Change the port number to desired port number. By default port no entry will look like: port=3306 You can change the value of port
Maven dependency for com.backstopsolutions - ant-get-free-port version 0.1.0 is released. Learn to use ant-get-free-port version 0.1.0 in Maven based Java projects
- ant-get-free-port version 0.1.0 ) in their Java project if it is based on Maven...; com.backstopsolutions - ant-get-free-port version 0.1.0 java library in your...-get-free-port released The developers of   com.backstopsolutions
ModuleNotFoundError: No module named 'port'
ModuleNotFoundError: No module named 'port'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'port' How to remove the ModuleNotFoundError: No module named 'port' error
ModuleNotFoundError: No module named 'port-for'
ModuleNotFoundError: No module named 'port-for'  Hi, My Python... 'port-for' How to remove the ModuleNotFoundError: No module named 'port... to install padas library. You can install port-for python with following
MySQL Default Port number
MySQL Default Port number  HI, What is MySQL Default Port number? Thanks   Hello, MySQL Server Default Port number is 3306. Thanks
What is parallel port
What is parallel port  What is parallel port and its used for what
port 8080 already used
port 8080 already used  Error Server failed to start for port 8080: Address already in use: JVM_Bind   It just means that your port is being used. So the solution is to free the port. There is a small softeare (just
mapr drill port number
mapr drill port number  Hi, What is the port number in Mapr for accessing Apache drill? I want to know all the mapr drill port numbers. Thanks   Hi, Here is the list of all the port of drill in mapr: Port Type
mapr drill port number
mapr drill port number  Hi, What is the port number in Mapr for accessing Apache drill? I want to know all the mapr drill port numbers. Thanks   Hi, Here is the list of all the port of drill in mapr: Port Type
Maven dependency for io.github.jan-tennert.supabase - gotrue-kt-android-debug version 1.3.2-no-port is released. Learn to use gotrue-kt-android-debug version 1.3.2-no-port in Maven based Java projects
-kt-android-debug version 1.3.2-no-port ) in their Java project if it is based...; io.github.jan-tennert.supabase - gotrue-kt-android-debug version 1.3.2-no-port in Java...; io.github.jan-tennert.supabase - gotrue-kt-android-debug version 1.3.2-no-port java
Maven dependency for io.github.jan-tennert.supabase - postgrest-kt-android-debug version 1.3.2-no-port is released. Learn to use postgrest-kt-android-debug version 1.3.2-no-port in Maven based Java projects
- postgrest-kt-android-debug version 1.3.2-no-port ) in their Java project... 1.3.2-no-port in Java projects. Follow the step by step tutorial for using... version 1.3.2-no-port java library in your project. ADS_TO_REPLACE_2 Now
Java Read username, password and port from properties file
Java Read username, password and port from properties file In this section, you will come to know how to read username, password and port no from... username=root password=root port=3306 Here is the code:ADS
Getting the Local port
Getting the Local port     ... port. Here we are going to make it easier to understand the step be step... it will display the server's local port. For which we use a class ServerSocket which creates
what is redis default port number
what is redis default port number  Hi, I am writing program in Python to connect to redis server and add/update data. I want to know the port number on which redis is running. Please help me in finding the default port number
ModuleNotFoundError: No module named 'brioa-port'
ModuleNotFoundError: No module named 'brioa-port'  Hi, My Python... 'brioa-port' How to remove the ModuleNotFoundError: No module named 'brioa-port' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'port-checker'
ModuleNotFoundError: No module named 'port-checker'  Hi, My Python... 'port-checker' How to remove the ModuleNotFoundError: No module named 'port-checker' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'port-eye'
ModuleNotFoundError: No module named 'port-eye'  Hi, My Python... 'port-eye' How to remove the ModuleNotFoundError: No module named 'port-eye... to install padas library. You can install port-eye python with following
ModuleNotFoundError: No module named 'port_killer'
ModuleNotFoundError: No module named 'port_killer'  Hi, My Python... 'port_killer' How to remove the ModuleNotFoundError: No module named 'port_killer' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'port-linker'
ModuleNotFoundError: No module named 'port-linker'  Hi, My Python... 'port-linker' How to remove the ModuleNotFoundError: No module named 'port-linker' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'port-range'
ModuleNotFoundError: No module named 'port-range'  Hi, My Python... 'port-range' How to remove the ModuleNotFoundError: No module named 'port... have to install padas library. You can install port-range python
ModuleNotFoundError: No module named 'port-scanner'
ModuleNotFoundError: No module named 'port-scanner'  Hi, My Python... 'port-scanner' How to remove the ModuleNotFoundError: No module named 'port-scanner' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'wait_for_port'
ModuleNotFoundError: No module named 'wait_for_port'  Hi, My... 'wait_for_port' How to remove the ModuleNotFoundError: No module named 'wait_for_port' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'brioa-port'
ModuleNotFoundError: No module named 'brioa-port'  Hi, My Python... 'brioa-port' How to remove the ModuleNotFoundError: No module named 'brioa-port' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'get-port'
ModuleNotFoundError: No module named 'get-port'  Hi, My Python...-port' How to remove the ModuleNotFoundError: No module named 'get-port... to install padas library. You can install get-port python with following
Construct a DatagramSocket on an unspecified port
Construct a DatagramSocket on an unspecified port...;Socket recive at available port");   }  ...;javac DatagramSocketExample.java C:\roseindia>java
Local Port Scanner
Local Port Scanner       This is a simple program of java network. Here, we are going to define... of  java.net package which takes local port number as argument. A server
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for ant-get-free-port version 0.1.0
-free-port version 0.1.0. You can add these depency in your project to get com.backstopsolutions:ant-get-free-port:0.1.0 Java library in your project.. Maven...-port version 0.1.0 In this section have given the dependency code for Maven
Low port Scanner
C:\rose>java LowPortScanner There is a server on port 135... Low port Scanner       In this section, you will learn how to get local port number
mysql port number other than 3306
mysql port number other than 3306  Hi, Can I change MySQL port number? What can be mysql port number other than 3306? Thanks
what port does the dns service operate on?
what port does the dns service operate on?  Hi, I am trying to find the dns server port. what port does the dns service operate on? Thanks
How to change default MySQL port in linux?
How to change default MySQL port in linux?  I have a sever and due to some reasons I want to run the MySQL server on the different port and not on the detault port 3306. How to change the MySQL default port on my Linux box
serial port communication using bluetooth in j2me
serial port communication using bluetooth in j2me   how to make serial port communication using bluetooth in j2me ? what r prerequisites
serial port communication using bluetooth in j2me
serial port communication using bluetooth in j2me   how to make serial port communication using bluetooth in j2me ? what r prerequisites
ModuleNotFoundError: No module named 'connect-sdk-haxe-port'
ModuleNotFoundError: No module named 'connect-sdk-haxe-port'  Hi...: No module named 'connect-sdk-haxe-port' How to remove the ModuleNotFoundError: No module named 'connect-sdk-haxe-port' error? Thanks   Hi
ModuleNotFoundError: No module named 'port-scanner-test'
ModuleNotFoundError: No module named 'port-scanner-test'  Hi, My... named 'port-scanner-test' How to remove the ModuleNotFoundError: No module named 'port-scanner-test' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'random-open-port'
ModuleNotFoundError: No module named 'random-open-port'  Hi, My... named 'random-open-port' How to remove the ModuleNotFoundError: No module named 'random-open-port' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'connect-sdk-haxe-port'
ModuleNotFoundError: No module named 'connect-sdk-haxe-port'  Hi...: No module named 'connect-sdk-haxe-port' How to remove the ModuleNotFoundError: No module named 'connect-sdk-haxe-port' error? Thanks   Hi
ModuleNotFoundError: No module named 'ephemeral-port-reserve'
ModuleNotFoundError: No module named 'ephemeral-port-reserve'  Hi...: No module named 'ephemeral-port-reserve' How to remove the ModuleNotFoundError: No module named 'ephemeral-port-reserve' error? Thanks   Hi
MySQL default port number in Linux
MySQL default port number in Linux - How to find the default port number... server and you are not aware on which port it is listening then this tutorial is for you. In this tutorial you learn "How to find the default port number
Serial COM Port Value in to database
Serial COM Port Value in to database  How save the serial COMport value in mysql databse. Following code is here. package simpleread; import java.io.*; import java.sql.Connection; import java.sql.PreparedStatement
How to change MySQL default port Windows?
How to change MySQL default port Windows?  Hi, I am learning JDBC and installed MySQL. Now I want to change the default port 3306 to say 3307 of MySQL. How to change MySQL default port Windows? Thanks   Hi

Ads