I wrote a little java program that establishes a socket connection (port 23456) over TCP between a server (pong.java) and a client (ping.java). I start the server and then the client which sends ping and the server responds with pong. This happens 50 times.
This works all fine but now i want to shut this down using a SYN Flood DoS attack with hping3, but i can't get it to work. I can easily stop a file transfer running between the client and the server over SMB with the same DoS program. The server definitely gets the SYN packages- When i attack the same port the java socket connection uses it just shuts the attack down and the java program happily finishes the 50 loops. i can't figure out why. is there some protection in java or do sockets in java work different than a TCP exchange over SMB?
I do this for a network class and i just can't figure it out. I just attack myself between 3 VMs so no one will get harmed.
I can provide the source code or further information if needed.
Thanks a lot if anyone can help.
I don't know whether it fits or not, however I wrote a server-client app and more clients were trying to connect. As long as I used the Sun JRE, it worked. With the OpenJava, I was unable to get it work - only the first client connected, the others had to wait. I was unable to figure out why, and didn't really care - installed Sun (nowadays Oracle) JRE on the server and it run smooth. So if you use Linux and OpenJava, I suggest give it a try with Oracle's JRE.
Related
I have a simple TCP server which I wish to connect with a TCP client. This is all programmed in java. See Here.
I used the ServerSocket.accept() method to return a socket with a port allocated by java. (I set it to 0, thus randomly allocating the first available port). However, when I wish to connect to my server via client, I can not find the port, because it is not saved anywhere or displayed on the server page. How can I know what port to connect to?
And for future reference when I wish to connect multiple clients, or when I am unable to see the server running in a terminal, how can I view the display the port to the public?
Thank you!
If you need any more detail, please ask. I am new to all of this, and I find it hard to put these concepts into words when I am only fairly comfortable with them.
I know how to make a socket between a server and client if they are both on my computer. What I don't understand is how to make a socket connection between a client on my computer, and my server running on a different network. I can't just do:
new Socket("Machine name", PortNumber);
right?
You can create a socket with a hostname or ip address. However this does not work in Java applets: They typically are restricted to only connect to the machine the web page has been loaded from. Similar restriction (Java does this with a special SecurityManager) applies to some old fashioned and strict application servers.
But with stand-alone Java programs nothing is stopping you from doing it. If you have problems it might be best to tell us what error message you get.
Is it possible to make my local computer function as a gateway in Java? I need the other local machines to connect directly to my computer to see if they are alive or not.
You could run a Java server program on your desired PC and let it listen on a port. Then you could use other programs (browser, other Java programs etc.) to connect to this port, and send commands to be executed by the Java server program.
If you just want to see if the PC is turned on or not, I'd just use the ping command though. Or see this answer: How to do a true Java ping from Windows?
Surely it's the other way round? Surely you want to connect to the other machines to see if they're alive? In which case see InetAddress.isReachable().
Try this.
Create a Java Server Socket, which keeps listening to the client at some port.
Write a client in Java which connects to the Server, wrap the connection logic in try-catch block....
If your host is alive the try code is executed which contains the code to connect to the
Server, if this connection process fails you will get UnknownHostException, here you can instead type a message that the connection failed.
You could more easily manage and control this by polling for other devices from a central server. If possible, avoid unnecessary client/agent apps that might tax your development and support resources as well as taking up RAM on the client workstations.
There are many monitoring tools that already do what you want. I'd have a look at Nagios, for example.
If you want to develop your own app, do your own quick troubleshooting, or just get a feel for network discovery tools, then take a look at NMAP. You could, for example, search a subnet for anything that responds to TCP:445 and see what Windows machines are alive.
If you do go the Nmap route, please have a look at Nmap4j on Sourceforge. It's a Java wrapper API that simplifies the work needed to integrate Java and Nmap.
Cheers!
Is it possible to write a Java applet that can be a server on the client machine within the client's local network?
To be more specific, what I am looking to do is tunnel non-web traffic over the web. The sender would send to the applet, which would then forward the received data back to the server.
Is this sort of thing possible? What are the restrictions that might get in the way?
Note: I know that the applet can connect back to the server, that isn't an issue. The issue is whether or not an applet can listen for a connection / data on a local, client-side port.
An unsigned applet can only connect the host they come from.
A signed applet can do any connection you want and can listen on tcp-ip ports.
Source : http://docs.oracle.com/javase/tutorial/deployment/applet/security.html
Server does not connect to anywhere. Server opens server socket and is listening.
In past as far as I remember the server socket was restricted in MSIE and was permitted in Netscape (do you remember such browser?) :)
I personally have not been writing applets for the last 10 years, so I have no idea what happens now with currently existing browsers, but it is very easy to check. Just write the shortest applet you can and put code new ServerSocket(1234).accept(); into its init() or start() method. If no exception was thrown you can write applet that functions as a server. Otherwise you cannot.
Just try it with all available browsers. 20 minutes work and you are done. Good luck. I'd will be glad to know about the results.
Generally, it cannot.
One reason why is that applets tend to be ran within security constrained environments, which means that they are denied the ability to open server sockets.
There are ways around such a restriction, basically you can specify a special security policy for the applet, or run it in a special unconstrained container; but why bother when you can just port the contents of your application into a standard servlet, or even a stand-alone server?
Ok guys im not that experienced so take it easy on me.
Ok so i have 2 programs, one for the server (my pc) and one for the client(other pcs)
and this is the setup
server listens/accepts > client connects > server sends command to client > client executes.
and thats it, after that it disconnects BUT i need the client to stay connected so the server can keep sending commands as needed.
How can i achieve this?
I can provide more info if need just ask!
thanks for all the help guys.
The server will receive a socket when accept() returns, and as long as that socket does not get closed then the connection remains open. The client will then run in a loop of read/execute-command until the server closes the connection. I can provide more details if needed.
There's a few official examples to get you started with Java sockets. Plus since its Java, getting this setup is pretty easy.
As Kevin already said, you'll open up a ServerSocket on some open port. Then call accept() which will return when a client connects with a Socket on the same port as the ServerSocket.
Also, make sure you pay attention to the specified host if you want the client program to connect from a computer different from the host. You might run into trouble with the loopback interface if you specify the host as "null" or "127.0.0.1".