This is my first post here, so I'm not quite sure what to say / ask. In any case, I am trying to create a simple java program that runs command line commands from a java program mainly used for ping flood (ping flood).
Here is my current code
public class Core extends JFrame { JTextField ipTextField; int packets = 0; boolean running = false; public Core() { super("Fatique"); Container container = getContentPane(); JButton bAttack = new JButton("Start Attack"); JButton bStop = new JButton("Stop Attack"); JPanel jPanel = new JPanel(); container.setLayout(new FlowLayout()); ipTextField = new JTextField("IP Address", 30); container.add(ipTextField); bAttack.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String input = ipTextField.getText(); String[] value = input.split(":"); int amountOfPackets = Integer.parseInt(value[1]); exec("cmd /c" + input + " -t -n " + amountOfPackets); running = true; } }); bStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { stop(); } }); if(!running) { jPanel.add(bAttack); } else { jPanel.add(bStop); } add(jPanel); } public void exec(String cmd) { try { Process p = Runtime.getRuntime().exec(cmd); System.out.println(getOutput(p) + " - " + getPacketsSent()); } catch (IOException e) { e.printStackTrace(); } } public String getOutput(Process p) { String output = null; try { BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = in.readLine()) != null) { output = line; packets++; } return output; } catch (IOException e) { System.err.println(e.getStackTrace()); } return null; } public int getPacketsSent() { return packets; } public void stop() { exec("cmd /c break"); running = false; } public static void main(String[] args) { Core c = new Core(); c.setSize(500, 300); c.setVisible(true); c.setResizable(false); c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); c.setLocationRelativeTo(null); }
I am new to java, so maybe I will not do what I want. I want it to be this, enter the IP address in the text box and divide it by ":", and after that the number of packets, for example
127.0.0.1:100
Although now, when I try to use this number of ip and packets, it returns "null-0" (from the exec method), and I'm not even sure that he did anything related to ping.
What I'm trying to accomplish is the same as I said, flood ping itself, and then output everything that I get as an answer, although I have no idea if this code really does something even with this, I'm in I mainly use logic when coding java.
public String getOutput(Process p) { String output = null; try { BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = in.readLine()) != null) { output = line; packets++; } return output; } catch (IOException e) { System.err.println(e.getStackTrace()); } return null; }
Can someone explain to me why my code is not working, how I want it to work? Please do not judge, as I said, I am completely new to Java programming.
EDIT: Here is a short “informative” explanation of what I'm trying to accomplish.
- I am dialing an ip address and how many packets I want to send. In this explanation, I use localhost ip and 5 packets.

I'm starting an attack. In this part, I want the program to run the cmd command line command
ping 127.0.0.1 -t -n 5
127.0.0.1 is the ip that I put in the text box in my program, and 5 is the number of packets that I put in the text box.
I started the attack, so this is what should happen on the command line: 
The language is Finnish, but still the same.
This is the main explanation of what I'm trying to accomplish, I hope someone understood and can help / say why my code is not working, or it works, but does not print the correct lines in the eclipse console.
java command command-prompt prompt ping
Woobie
source share