networking in java for client server communication - java

I need to make a troubleshooting tool in java
From the java code, I need to communicate with tethereal (linux commands) to help me generate a .pkt file. The .pkt file will contain all the contents of the communication that took place between the client and the server- i.e. all the packet communication between the client and server.
how should I do that?

Do you know WireShark? That is a cross-platform Network Packet Capturing application.
The idea is that it captures all packets (TCP and UDP) that passes one network device (eg: WiFi card) and you apply a filter on the port that your application uses, and eventually an IP address. Very useful tool.

If you really need to do it in java you can use http://jnetpcap.com/ which is a wrapper for libpcap which works similar to tethereal.

Related

Packet Sniffer/Filter in Android using VPN

I want to build a sniffer in Android and one of the approaches that was proposed was a loop-back VPN.
The issue with this approach is that all the communication with the outside world will be done through a protected socket and in Java I still cannot sniff low level TCP information from that socket.
For example, I cannot find out when exactly an ACK was received for data that was sent from the phone. Am I missing something or is this approach simply not suitable for a proper sniffer?
You won't be able to get ack information and other low level info using an Android VPN as this data won't be exposed through Java sockets.
An alternative is to utilize a native sniffer (TCPdump is one example, and an Android port already exists), execute it as root from your Java app and then retrieve its output in your app

UDP packet capturing on a servlet application running at GAE

I have a code running in router that sends UDP packets(using Sendto() function and a string of data) to a particular server whose IP address and port number I will mention in my code.
I want to deploy a server application that could receive a UDP packet and store its information on server or somewhere else not sure right now.
I have decided to use Google app Engine for hosting my server side code which most probably will be having something like recvfrom() function to receive string.
So how and by using what API's can I start developing my server side code.
Google App Engine has a Preview release of a Socket API, but it does not let you create listening sockets. See Limitations and restrictions section at https://developers.google.com/appengine/docs/python/sockets/
You cannot create a listen socket; you can only create outbound sockets.
You can use Google Compute Engine to run any reasonable software on Google's cloud platform, including programs that receive UDP datagrams. You must always pay for Compute Engine instances.
According to the newest edition of App Engine Socket docs for Java, if you're using java 8 runtime you should be able to use java sockets without limitations:
Applications in the Java 8 runtime default to using native Java
sockets with no restrictions: Google recommends that you keep this
default.
That means that it should be possible to use java.net.DatagramSocket or java.nio.channels.DatagramChannel freely to work with UDP.

Changing tcp/ip packets c++ or java

Here is the situation. There are server and client in network. They communicate like this:
Client sends request for some function.
Server sends to client function parameters.
Client trying to perform function and sends answer to server.
Server sends to client data which it should show.
But sometimes client can't perform function and sends error. I want to catch all packets from step 2, analyze them (I've already have tools for that), prevent some of them to reach client, process them with my program and form packet like in step 3. This must be done on client side. I have no access neither to server nor to client.
So, the question is: Is there libraries for changing, injecting and removing tcp/ip packet in c++ or java? The solution should be working in both Win and Linux systems.
Also, may be you have better ideas to expand client functionality?
Thanks for any help!
I tried to google how to change packets, but all I got were unanswered questions and sniffers=(
Edit: Actually, I don't really need injecting and removing packets, I can manage it with only changing packet data. Also, there is no multiple requests in the same packet, and a single request across multiple packets is not a problem.
You have to build a Proxy for your server. The client connects to the proxy, and the proxy itself connects to the server. It just routes all the packages between client and server.
BUT it is now able to intercept specific messages and to modify them. Imagine a filtering HTTP proxy, it works the same way.
I have personal experience with libpcap on linux and freeBSD, a kind of lowlevel library that helps to catch or inject packets. I did use it in an IPV6 network bridge project... But i know there is a windows port for it.
http://sourceforge.net/projects/libpcap/
You can let the library to:
catch packets using a filter
extract data from packet
you can process the data (modify them)
reinject it again using the same library
But you would have to work with internal data in a quite raw matter. Best documentation for this library are comments inside its header file, that is the most up to date info. Maybe there are some more comfortable highlevel libraries.

rtsp server forwarding

So I am trying to stream a webcam feed from my computer to my android phone. I am using a simple forwarding server to connect the two so that I don't have to worry about home network IP firewalls ect. I am using FMJ to capture the video feed and was thinking rtsp protocol would be best because android supports reading it. My problem is I dont know how to forward the information via the server, is it as simple as forwarding UDP packets? all programs involved are implemented in java btw.
Use Netty. It is very easy to create an RTSP server with this library. For hints see the sources here.
Or you can port my library which is written in C#
http://net7mma.codeplex.com/
CodeProject article # http://www.codeproject.com/Articles/507218/Managed-Media-Aggregation-using-Rtsp-and-Rtp

Make two Java applications on the same LAN aware of each other

I have a Java program running on two computers that are both on the same network. I would like to have these applications become aware of each other, so they could communicate directly as opposed to communicating with the server to relay messages.
I believe i may have a solution as to how this would work, but am unable to find any examples to compare my solution against. Do you guys know how this problem is usually solved?
There is a good library that implements the Zeroconf / Bonjour standard in plain java at http://jmdns.sourceforge.net/
This basically relieves you from the protocol burden and allows you to advertise and lookup service providers based in logical names (That's what iTunes or Mac printing does for example).
This book http://www.amazon.com/Zero-Configuration-Networking-Definitive-Guide/dp/0596101007 explains all basic concepts.
You could get them to do a UDP multicast within a LAN environment to identify the programs using protocol messages then have a stored cache of each other's identity and then use TCP to connect and do main exchanging of messages (which is more reliable than UDP). Or you can simply proceed with UDP messaging only if you want to.
You can search for multicasting in Java online.
Some multicast related links:
http://download.oracle.com/javase/1.4.2/docs/api/java/net/MulticastSocket.html
http://www.javafaq.nu/java-article817.html
A good multicast chat software you can reference:
http://sourceforge.net/projects/mc2/
One way would be to send a broadcast to see who's out there, then implement a GUI to show the user what other peers are there and give an option to connect to. (The broadcast will give you the IP address of everybody there.)
Once you know who to connect to, you simply open a TCP connection (or use UDP if it is time-critical) and you're done.
Btw, this is for IPv4 - IPv6 doesn't have broadcast (although something similar).

Categories

Resources