I am researching how to build an Intrusion Prevention System (IPS) application using Java, however I don't know how to redirect Internet packets from a PC to my application and read the packets. The data format I'm looking to get from the packets is similar to the data that Wireshark produces. How would I go about getting low-level packet data like this in a Java application?
Unfortunately, Java does not have access to "raw sockets"--the kind of access you need to get the details you'd expect from a Wireshark dump or the similar.
If you need to use Java for the rest of your application, consider using JNI (link is to a good JNI tutorial). It allows you to use C/C++/Fortran code within a Java application, so you can make system calls and get the kind of access you need.
Related
I am trying to stream media from a server to a client. I was going to use RTSP, but in RTSP the client tells the server what to do.
I need to be able to control the media the client gets from the server. The Server tells the Client what music he wants to play.
Is there an other protocol I can use or an other way I can work around? Maybe I am wrong and you can still do this using RTSP. I need to use UDP, as I need to use multicasts, and I dont want to have to build my own protocol to keep the client synchronized.
If you need more infos, dont hestiate to use the comments field below!
Edit
This application is done in Java. I would be happy, if you could maybe tell me a mechanism that works well with Java. I am currently using the Netty library, which looks to be pretty useful (although I have not figured out how to use it yet). I don't need an answer that is based on pure network knowledge, I know how I could build a whole streaming ecosystem. I need to get this working on Java 8, without having to do the handling of the basic protocol stuff myself.
Take a look at libjitsi which is an open source Java audio/video library which can be used for streaming with encryption. It does not use Netty but it looks to be mature.
I was going to use an objectOutputStream but heard this is unreliable because different java versions might deserialize objects differently. Something about 'horrible cross-architecture practice..'
So how else can I send objects and arrays between these devices, where the receiving end can piece back together the proper object or array data?
Edit: Just read what you are doing. You might not need a web server. A lot of people recommend one because of the massive support web servers have. You certainly use TCP or UDP to talk between a server and a client. You'll need to have some protocol if you want data interchange, and most people here would be familiar with XML or JSON
If you need inspiration, try looking at a few protocols like FTP, or even Bittorrent
Web Server case:
I wrote a Java web server for a college homework assignment. A web server actually be quite simple if you have a good grasp on TCP/IP. The code scattered everywhere online to do it though gets a little hard to decipher what exactly is going on, but once you do, it's not bad
You definitely should check out the RFC for HTTP, even though those tend to be worded in legalese. Beyond that, on the server, you basically read strings in line-by-line and you should be able to figure out what to do on the server (example GET /somefile.html HTTP/1.0). Just do System.out.println on those lines and go from there. The same goes for client code. You also can use telnet to see what a web server does
To test, I would actually recommend trying just a regular web browser like Firefox, Chrome, IE, Safari, and even curl scripts. This is an easy test to see if your server is running correctly
As far as data interchange goes, XML or JSON would be recommended, mostly that if you learn how to handle it, you get 100 experience points for your resume. However, to get things started, you can start out just by sending and receiving text like "Wazzzaaap". Web browsers can also grab XML and JSON data.
By 'java server', what kind of protocols are you using?
One option is RPC, which is defined in java.rmi
If you are using http, the simplest choice is to implement a small servlet in tomcat/jetty and use restful services
The data format can be xml, json, bin, etc
I am trying to set up a webserver on an old machine of mine. I have installed ubuntu server edition and aim to use it for the following:
I want to run a java program on the server. I want to be able to retrieve data from the program from another computer/phone using an internet connection. I also want to be able to give the program data, and get a response saying whether or not the data has been received correctly.
So for example:
A .jar program runs on my server and holds a variable x
I want to be able to query the value of x from another device (over the internet).
I want to be able to set the value of x remotely from another device, and get a response saying it was successful in altering the value.
What are my options here? I would like to try and keep things simple. It is perhaps worth mentioning that I will be the only one using the system. The server will be used exclusively for dealing with the two requests outline above.
Is it simply the case of creating a java program that listens out for incoming requests and running that on the server?
As you mentioned, you can start with custom ServerSocket wrapper which will decode incoming requests and do as it's bid. Currently, whole frameworks are done to encapsulate common code of this task -- see my 3rd point.
Old-school java solution: use RMI. See RMI tutorial.
New-school java solution: devise some simple text-based protocol with 2 commands:
Read()
Set(newVal)
Then implement that protocol over some new trendy Java framework, like Apache MINA, which is created specifically to facilitate quick development of network apps in Java.
I, personally, started with RMI for such kind of tasks. Since RMI is considered Core Java technology, it's wise to learn it.
I have a Java applet that runs on visiting a site, whereupon it receives, parses and displays streamed data. Unfortunately said applet isn't particularly well designed and I would like to extract the streamed data to make it more useful for myself.
In order to do this, I need to get insight into the connections made, data being exchanged, the state of variables in use and so on, so that I can replicate the log in and streaming.
So far I've been using Wireshark for network traffic, Java Debug Console and eyeballing the applet source installed on my system but still without success- primarily because there is a series of connections being made to the remote server and I am unsure the exact nature of the requests (and responses) and the variables contained.
Does a suitable app exist that can provide such insight?
I should add that I have no experience developing with Java, my knowledge is in Python, mainly.
Is there a way I can pass data, from Java server code, to a Java program which is already running?
I need to transfer data in real time, and I cannot integrate the two programs as they use a different compiler.
Any ideas?
Thanks
** ADDED INFO **
I am looking to control a robot over the internet. I have the server code which communicates with the client, and a program coded in a unique type of Java code (LeJOS if anyone is familiar with it). From the server side I need to pass data to the PC LeJOS Program in real time. Hence, the LeJOS PC program must be able to receive some data from the server code, whilst it is running.
Is this possible? To clarify, both the server code and the LeJOS PC Program will be running on the same machine.
Another possibility could be to integrate the server code and LeJOS PC program into one, so that the LeJOS PC program is run directly from the server code. Would it be possible to do this?
Thanks!
Hm, that's a pretty broad question, and it really depends on what the restrictions are on your app. Basically you're doing to have to transfer it through some intermediary channel.
Options:
Have the server write the data to a file, and have the Java app read it
Have the Java app connect to the server via a Socket and read the data
...and going to much more complicated methods:
RMI (Remote Method Invocation)
If you need a more specific answer, you'll have to tell us more about:
why are you transferring this data?
what sort of data you're trying to transfer between the two apps?
do you have access to modify the two programs, or is their code not controlled by you?
what have you already tried?
Have the client connect to the server via a socket. It doesn't matter if they're both running on the same machine or not. That is pretty much they way you do 'ipc' in Java, and if you want to extend the control over the network you'll have to go there anyway.
You can send data bidirectionally, so its up to you how you want to use that. The simplest way to implement your protocol is something textual, that way its easy to debug. If you can make it request/response oriented then that makes things simpler too.
Here's a basic tutorial for network IO in Java. http://docs.oracle.com/javase/tutorial/networking/sockets/index.html
Good luck.