Can any one suggest me a packet blocking software ??
My requirement is to block packets within the LAN.(Internet does not come into picture).
Supposing CLIENT_A communicating to CLIENT_B in the same network(LAN).
I want a CLIENT_C (who is in the same network) to capture(I can use jpcap library's sniffer for this purpose) and block packets sent by CLIENT_A to CLIENT_B.
How do i block packets over LAN..?
Thank you in advance.
Regards,
Veenit Shah
This kind of thing is normally done using a separate firewall (e.g. in a router or gateway box) or firewall software running on one or both of the client machines.
This is not the sort of thing that it is sensible to implement in Java.
EDIT - in response to this followup
I am aware that such a thing is not advisable in Java..but still ill have to implement it..so is there any means to do so..?
Let us assume that you are talking about implementing a client-side firewall on a Linux machine. I can think of two approaches:
You could use Process.execute() and friends to run the Linux iptables(8) admin utility which manipulates the OS kernel's network packet filters. This is the simplest Java-based approach. But it requires that your Java app runs as root.
You could reverse engineer what iptables(8) is doing to manipulate the packet filters and code the same functionality in Java. That would be more coding work, including implementing parts of the functionality in C via JNI or JNA. And your app needs to run as root.
But a far, far simpler approach is to simply run iptables(8) from the command line, or make your changes using the fancy GUI-based admin tools.
Note that in the scenarios above, the firewall itself is not implemented in Java. All you are doing is administering the firewall from a Java application. I cannot think of ANY way to actually do the filtering / blocking in Java that is even remotely practical.
You may need some arp attack things to redirect packets from CLIENT-A to Client-C instead of CLIent-B.
I don't think this is a good idea.
If you are reading the packet on the network on Client C, Client B has already received it so it is too late to block it. If you are using switched ethernet, then Client C wouldn't even see the packet that was sent to B anyway.
The only way to do this is to have A communicate to B through C then C can decide if packets should be sent. This is called a firewall. Instead of writing one, you could use iptables on Linux to do this.
But to make use of this, you need to understand how the network works and I'm not sure you do at this point based on your question. So you will need to learn a lot about ethernet (assuming you are using ethernet) and the different networking layers. I'm not sure of a resource for this.
Related
I want to connect my PIC micro controller to computer via serial link and control it. The MCU will send a series of bits, my program should extract useful information, so basically i should be able to work on individual bytes of received data and send some commands back. So where should i begin to write such a program ?. I have worked on C programs and simple java programs and i know bit of PHP.
It will be much better if i can make it more like a webpage so that i can host a page on my computer which can be accessed by all devices in the network and control the mcu.
Please suggest me some ideas to implement the same
If I were you, I would consider dealing with PIC or other microcontroller, because they are very low level hardware. There are some options like Arduino, RasberyPI, etc. They already have LAN or WiFi modules and cheap as well.
I would do it in a Service oriented way, so communicate via TCP/IP or UDP socket. In this way, you will have a standard interface. No mather what harware/software you have.
One way of going about it:
write software to interface your micro-controller with your computer
the pc side of the interface is most likely written in c, so learn how to interface java and c with something like jni or jna
look into java ee to create a web server
It will be very broad and require a fair amount of work/learning.
I am coding a program that necessitates having two machines talk to each other via TCP.
I have a (very) basic familiarity with the java.net Socket classes and related things. I am worried about routers/firewalls blocking the connection. All I need to do is get a port open in order to use the Java STL Socket classes.
I was told to look into using upnp by a friend, and another stackoverflow question regarding upnp suggested using Cling. As a network programming novice, Cling seems like overkill for this (and I am not advanced enough to fully understand the manual).
I am sorry if I am asking the wrong question, looking in the wrong place, etc. All I want to do is connect two machines to send some floats back and forth without having to manually go into my router and forward ports.
Is there anything in the STL that does this automatically, or any simple libs?
First thing first: there's no such thing as "STL" in Java. You're probably referring to the basic Java SDK.
Second, you are asking for "simple means" to perform an operation that is, from a networking point of view, not trivial at all. Look at the most basic task that one of your programs (program A) will have to do: denoting the network location of its "target" (program B). If program B is behind a router, what do you know about program B's network location? nothing. All you know is the router's address.
Same with firewalls. You're concerned about firewalls blocking your connection? well, if your firewalls are any good, then you want them to block all connections except for pre-approved ones.
For programs separated by a NAT, the only sensible method to go about doing what you're looking for is to use UPnP. If Cling is an overkill, try something like weupnp.
There's no free lunch, though.
If there is no network "masking" device (such as a router) between program A and program B, then very simple TCP/IP programming using the Java SDK should just work. If there are networking devices along the ways, you'll have to cope with them by means of configuring your devices, or using UPnP.
I would take a long look at the following tutorial: http://www.giantflyingsaucer.com/blog/?p=224
The idea here is that a library called xsocket creates events that trigger when new information arrives.
I'm developing a distributed application, and I need to connect a client Java based to a server C++ based. Both of them will need to send information to each other, but I need them to be able to do things while waiting for the information, and they don't know when they are gonna get new information, or send information.
How can I achieve this? Now I'm trying to implement a basic communication with Sockets, but I don't really get to communicate them. I have read that using sockets + threads is usually a good approach for client-server apps.
Could you please recommend me some web or book to read about this, or send me some example code to learn?
Do you think that i should use other approach, better than sockets? maybe a higher level library (i would need it for c++ and java) or a totally different way?
EDIT:
I will add some extra information.
What I would love to achieve is the following:
My C++ program has a main loop, where I would like to have a call like GetUpdatedDataFromRemoteDevice() where I read the new values of some numerical variables that previously got updated from the net (the socket, for example).
Eventually, the C++ program will need to send a message to the remote device, to tell him to send other kind of data, and after that, keep getting the updated values.
From the Java program (remote device) the application running is an interactive touchable screen, that cant get blocked by the network transmissions, because it must keep working for the user, so all the networking should be done in a separated thread.
That thread, should connect to the server, and when a button is pushed, start to send the data (4 changing numerical values) in a loop until another event happens.
It would be nice also to be easily re-connectable to the server.
ICE is a modern and good library for distributed applications:
many languages as C++ and Java
many platforms
GNU GPL
good performance
easy to use
First, you define the messages you want to exchange between server and client.
Then, you implement the C++ and Java source code to handle these messages.
More info at http://zeroc.com/ice.html
Have fun ;-)
EDIT: I have to use ACE in some projects. I can tell ACE is very old, maybe mature, but uses outdated C++ coding rules :-(
Therefore ACE is not as easy to use as STL or BOOST. Moreover, ACE is not really efficient... I prefer ICE ;-)
I don't know what your application is but robust client server socket programming is pretty hairy task to do properly. Hardware byte order, String encoding, Network errors, retries, duplicate messages, acks etc.. require lots of good design and careful programming. You need to get it work well as single-threaded before even thinking using multiple threads.
Unless you need instant notifications from server to client I suggest that you use HTTP as protocol between client and server. Client can poll server occasionally for new messages.
Anyway the problem has been solved multiple times already.
http://activemq.apache.org/
http://www.rabbitmq.com/devtools.html
http://www.cs.wustl.edu/~schmidt/ACE-overview.html
I did something of this sort once. In my case it was easier to connect my C++ app to a local Java app using JNI and then have the two Java apps talk to each other.
I want to communicate between two computers that aren't on the same network, i tried to use sockets, but I only found tutorials and examples for communicating in the same network.
I tried to search on stackoverflow, but I had no clear idea of what to search for.
I want to send text two-way (chat).
-edit- The thing is, it is to me vague what I have to use or do, so I can't be much clearer then to say I want to send two way text (perhaps date) for a chatapp, just to learn from.
-edit-
To communicate between two machines, they have to be on the same extended network. The only other option is to save data to external drives, e.g. USB drives, and you can attach to the second machine and up load.
You can use sockets to communicate with any other machine with an Internet connection, provided your firewall(s) and configured to allow the connection. The whole point of a firewall is to prevent unauthorised access. I suspect this is your real problem. If your firewalls prevent access, you should not be able to get around this using Java (google network hacking for alternatives ;)
Another option is to use a service such as email if the two computers cannot talk to each other directly (they still have to be connected to the same network) This is much more complex than using a direct connection but it can be done.
I suggest instead you configure your firewall(s) correctly and you will be able to use plain Sockets.
You have to get the external IPs (there are sites which while visiting give you this IP), and hope that the firewall allows communication. Typically one should use a port above 1000.
There should be peer-to-peer libraries.
Another way is via SSH on one computer (JSch is one java library for SSH).
The easiest way is email exchange: the javax.mail API is compact but not the easiest. (Especially you could easily delete all mails, as I did once.)
This question is more concerned with the general design of a program. I have a problem in hand in which a centre communicates with a set of clients individually (the clients do not directly interact with each other).
The content of the communication between the centre and a client is entirely numeric, i.e. a bunch of numbers are sent back and forth. The clients are run on individual computers, and the centre can be hosted on another machine (or otherwise). The style of communication is iterative and synchronous in a sense that the centre sends a request/question msg to each individual client and the user of a client provides an answer/reply back to the centre within a time limit in each iteration, and this interaction repeats itself for a number of times until the end.
The centre does some calculation given the responses received from the clients, and the clients simply provide the inputs to that calculation.
I wonder what is an elegant design for this problem using Java? Any comment or suggestion is much appreciated. Many thanks.
I'd use KryoNet which can efficiently serialise your datasets over RMI invocations (remote method calls). Using it myself, and it works well. Has UDP and TCP without any mucking about. Start from the example on the site and work from there. You can easily get both sides of the connection working with RMI.
Sounds the MPI is right for you. Here is a Java version.
Good luck and Regards.
The simplest solution in pure Java is probably to use RMI. Just expose an object via RMI and have the clients call methods on it remotely.
If you want asynchronous behavior, you can use a JMS implementation or roll you own using sockets and TCP/IP as mentioned above.
If you don't like any of those, the MPI mentioned above may be for you. Or possibly Apache Hadoop may be for you.