aplicacion en java

Iniciado por Ancasu, 27 Septiembre 2017, 23:03 PM

0 Miembros y 1 Visitante están viendo este tema.

Ancasu

Hola foro, estoy haciendo una aplicacion sencilla en java que permita hacer  ping a una direccion, pero  cuando hago ping a cierta direccion ip que esta dentro del rango de mi red y que no esta "ocupada" este lo reconoce como si hubiera hecho  un ping de forma correcta, hice un ping desde la terminal a la misma direccion no ocupada y aparecen como enviados: 4 paquetes - recibidos: 4 -  perdidos: 0   :huh: :huh:; porque pasa eso si no hay un equipo que tenga asiganada esa direccion? . pienso que hay esta el fallo, pero no se como resolverlo atraves de codigo, que consejo me puede dar?

Ahora queria mostrarles el codigo por si ven algun error o como puedo solucionar el problema de cuando hay host de destino inalcansable, como esta el codigo lo clasifica como que se realizo el ping.

package ToolNetworks;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
//import java.awt.event.ActionListener;

public class ToolNet extends JFrame implements ActionListener {

private JLabel label1, label2;
private JTextField textfield, textfield1;
private JTextArea textarea;
private JButton boton;

public ToolNet() {

// titulo herramineta:
setLayout(null);
label1 = new JLabel("UTILIDAD DE RED:");
label1.setBounds(50, 20, 300, 30);
add(label1);

// campo donde el usuario guarda la ip a hacer ping
setLayout(null);
textfield = new JTextField();
textfield.setBounds(10, 50, 220, 20);
add(textfield);

// setLayout(null);
textfield1 = new JTextField();
textfield1.setBounds(10, 300, 220, 20);
add(textfield1);

// muestra ping
textarea = new JTextArea();
textarea.setBounds(10, 100, 220, 100);
add(textarea);

// BOTON DE RESPUESTA
boton = new JButton("Ping");
boton.setBounds(150, 220, 80, 20);
boton.addActionListener(this);
add(boton);

// ActionListener ping = new ping();
// boton.addActionListener(this);
}

public void actionPerformed(ActionEvent e) {

if (e.getSource() == boton) {

InetAddress ping;
String ip = (textfield.getText());
try {
ping = InetAddress.getByName(ip);
if (ping.isReachable(5000)) {
textarea.setText("responde");
textfield1.setText(ping.getHostName());
} else {

textarea.setText("no responde");
}
} catch (UnknownHostException e1) {

textarea.setText("Inaccesible");

} catch (NullPointerException npe) {
textarea.setText("Inaccesible");
} catch (IOException e2) {
textarea.setText("Inaccesible");
}

}
}

public void actionperformed(ActionEvent e) {

}

public static void main(String[] args) {
// TODO Auto-generated method stub
ToolNet formulario = new ToolNet();
formulario.setBounds(0, 0, 260, 300);
formulario.setResizable(false);
formulario.setVisible(true);
}

}


cuando hago ping a otra red que no existente, lo clasifica de forma correcta como "no responde"  esa parte esta bien  ;).


Gracias de antemano por cualquier aporte que me ayude a solucionar o enteder mejor como solucionar mi problema gracias....
¿Podrá la tierra soportar la población mundial?