Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Ethernet port in java

Have Programming Question? Ask it here!
 
 
 


DeepShikha
Ethernet port in java
2 Answer(s)      4 years and 4 months ago
Posted in : Java Beginners


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..........

Advertisement
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
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
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 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
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
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
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... password=root port=3306 Here is the code: import java.io.
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
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
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
Low port Scanner
Low port Scanner       In this section, you will learn how to get local port number... the massage on the command line very low port information. The java.net package
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
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
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
MySQL default port number and how to change it
What is default port number of MySQL Database server? This tutorial will explain you about the default port number used by the MySQL Server... database server by providing the port number in your program. You can also
jar file not reading input from serial port
for getting data from serial port. JOptionbox with "port not found" message is shown... from comm port. why it is happening? i attached the coding i used. public class...)) { JOptionPane.showMessageDialog("Found port: "+defaultPort
jar file not reading input from serial port
for getting data from serial port. JOptionbox with "port not found" message is shown... from comm port. why it is happening? i attached the coding i used. public class...(defaultPort)) { JOptionPane.showMessageDialog("Found port: "+defaultPort
How to get xml file form http port using web service
How to get xml file form http port using web service  hi I am suresh i am using netbeans 6.9 to develop a web service for getting xml from http port and use the xml data to convert it to java file and store it to DB. But i am
VoIP Phones
of a conventional phone jack, it has an Ethernet port through which it communicates...; VoIP Phones Skype Adopter An Ethernet hard phone is a self... the hardware store. I purchased a roll of Category 3 cable, a box of 3 port
Change port from 8080 to 80 in Apache tomcat - WebSevices
Change port from 8080 to 80 in Apache tomcat  Hi, Could you please tel me how to Change Apache Tomcat port 8080 to 80. Right now its running on port 8080. i want to change the port to 80. Please tel me how to change the port
Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1 - JavaMail
Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1  package beans; import java.io.*; import java.util.*; import javax.mail.... is "javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port
JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use.
JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use.  Deployment error: JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use. How can I solve
JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use.
JBoss Application Server Start Failed. HTTP Connector port 8080 is already... Connector port 8080 is already in use. How can I solve it? How can I kill the process that uses the port 8080 from dos prompt
JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use.
JBoss Application Server Start Failed. HTTP Connector port 8080 is already... Application Server Start Failed. HTTP Connector port 8080 is already in use. Deployment error: JBoss Application Server Start Failed. HTTP Connector port 8080
JBoss Application Server Start Failed. HTTP Connector port 8080 is already in use.
JBoss Application Server Start Failed. HTTP Connector port 8080 is already... Application Server Start Failed. HTTP Connector port 8080 is already in use. Deployment error: JBoss Application Server Start Failed. HTTP Connector port 8080
i have installed oracle 10g (both ee and xe) editions... while am installing i found port num as 1521 for ee, 1522 for xe
i have installed oracle 10g (both ee and xe) editions... while am installing i found port num as 1521 for ee, 1522 for xe  i have installed oracle 10g (both ee and xe) editions... while am installing i found port num as 1521
java project - JavaMail
java project  i want to make a project in java on ethernet mailing system.....can you provide the source code of this?and give me more suggestions to make
SWTCalendar
SWTCalendar         SWTCalendar is a port of Kai Toedter's JCalendar to Eclipse's SWT. It is a GUI date picker for Java using SWT as the GUI toolkit. SWTCalendar
Construct a DatagramSocket on an unspecified port
Construct a DatagramSocket on an unspecified port...;datagram Socket recive at available port");   ...:\roseindia>javac DatagramSocketExample.java C:\roseindia>java
JAVA CORE - Java Beginners
JAVA CORE  what is the library function to take input from parallel port of laptop in JAVA
Java
Java  what is the difference between a servlet and jsp? or relation between them? how to execute .jsp file without .java file when we doesn't know the port number
java
java  i have connected a mobile to my computer using COM port and i want to get received message to my java application can u please help me
about value taken in java database - JDBC
about value taken in java database  how to take value from Serial port communication Hyperterminal to the java database
JAVA - Java Beginners
JAVA  How to read port number using property file in JAVA?  Hi Friend, In data.properties file,put username=root password=root port... = prop.getProperty("username"); String pass = prop.getProperty("password"); String port
CREATE AND WRITE FILE THREAD JAVA
make this program in java with threads. I need to create a file and write in it (i know how to do that) but by listening in some port all the data that is being... a beginner :(   It has to listen from any port **port=6001 (example) Filesize
Multicasting in Java - java tutorials,tutorial
Multicasting in Java In a datagram network, Multicast is the transmission... in Java, be it unicast, broadcast or multicast, one needs a java.net.DatagramSocket... of a multicast address. One can optionally supply a local port
socket class in java - Java Beginners
.... i have used localhost and port as 2010.... if again i connected in that port it is saying already the port is used.... now my question is how to close the port after it is used...?? plz...help me
TightVNC Java Viewer connection
TightVNC Java Viewer connection  I have source code of the tight VNC..., it asked for the host and port so I passed following credentials: Host: 127.0.0.1 Port: 5800. Then I can see the status as connected on the console of my
java - Java Beginners
to the port of the machine where ServerSocket is listening. 2) The socket provides...: http://www.roseindia.net/java/network/serversocket.shtml http://www.roseindia.net/java/network/client-socket-information.shtml Thanks
EchoClientSocket
the hostname port number of a local machine. This program defines the IOException... and port number. If the machine supports both arguments then Client socket information will be displayed on command line such as local port number
WebServer - Java Server Faces Questions
WebServer  What is WebServer? Do i need one for the Java programming...;. Here 8080 is the port number. This is the default port number. You must check the port number while installing tomcat.Answer
 

 

 

DMCA.com