Ask Experts Questions for FREE Help !
Ask
    Gastonnn's Avatar
    Gastonnn Posts: 1, Reputation: 1
    New Member
     
    #1

    May 6, 2014, 01:29 AM
    Send a ping to multiple ip adresses
    hey,i made a java program wish takes a list of ip adresses from an XML file and then send to each one of them a ping in order to take out the value of time from each one.now the problem is with the output(i want to print write the values of time in a form of a matrix in a text file) here is some of my code and i would be glad if someone helps me out:



    public void actionPerformed(ActionEvent evt) {
    private boolean stop = false; // start or stop the ping
    stop = false;
    try {
    final Formatter x = new Formatter("C:/Users/VAIO/workspace/tcc/gastoon/kkk.txt");
    PrintWriter writer;
    writer = new PrintWriter("C:/Users/VAIO/workspace/tcc/gastoon/kkk.txt");

    for (int m = 0; m < 10; m++) {
    if (stop) break;



    DocumentBuilderFactory BuilderFactory=DocumentBuilderFactory.newInstance( );
    DocumentBuilder db=BuilderFactory.newDocumentBuilder();
    Document doc=db.parse("C:/Users/VAIO/workspace/tcc/gastoon/adresStore.xml");
    doc.normalize();


    NodeList rootNodes=doc.getElementsByTagName("connection");
    Node rootNode=rootNodes.item(0);
    Element rootElement=(Element) rootNode;

    NodeList l=rootElement.getElementsByTagName("users");
    Node users=l.item(0);
    Element element=(Element) users;

    NodeList nl=element.getElementsByTagName("user");
    List<String> allIps = new ArrayList<String>();

    for(int I=0;i<nl.getLength();i++){

    Node user=nl.item(I);
    Element ele=(Element) user;
    String adrss=ele.getElementsByTagName("ipAdress").item(0) .getTextContent();//+" -n 1";
    allIps.add(I, adrss);

    }
    for(String n : allIps){

    writer.print(allIps);

    for(int I=0;i<allIps.size();i++)
    {
    String pingCmd = "ping " +allIps.get(I) +" -n 1";
    String pingResult = "";
    String str="";

    try {
    Runtime r = Runtime.getRuntime();
    Process p = r.exec(pingCmd);


    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null){
    pingResult += inputLine;
    }

    String[] lines = pingResult.split("\n");

    for (int k=0;k<lines.length;k++) {
    String line=lines[k];

    if ((line.contains("temps=") && (line.contains(allIps.get(I))))){
    int index = line.indexOf("temps=");
    String time = line.substring(index + "temps=".length(),line.indexOf("ms"));

    writer.print(time);
    writer.println("\n");

    System.out.println(time);
    }
    }
    }
    }
    catch (IOException ie) { System.out.println(ie);
    }
    }}
    writer.flush();}}

Check out some similar questions!

How do I send Emails and such to multiple people with their website [ 10 Answers ]

How would I send an Email(s), I've received to multiple people Ex; such and such to... @.. such and such@.. such and such@... and so on?

Outlook express 6 mail send multiple copies [ 1 Answers ]

Sir in my computer Outlook express 6 Having send the multiple copies of same mail... It creates the lot of problem

How to get adresses? [ 3 Answers ]

Hey does anybody know from wer to get the adresses of film directors?


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.