wesley 29 de ago. de 2009
Olha se isso te ajuda…
import java.awt.Color ;
import java.awt.Container ;
import java.awt.GridLayout ;
import java.io.IOException ;
import java.net.InetAddress ;
import java.util.ArrayList ;
import java.util.List ;
import javax.swing.JFrame ;
import javax.swing.JTextArea ;
public class IP extends JFrame {
private static final long serialVersionUID = - 3698253747230767087L ;
private final JTextArea textArea ;
private final List < String > listIP ;
public IP ( final List < String > listIP ) {
this . listIP = listIP ;
textArea = new JTextArea ();
textArea . setBackground ( Color . BLACK );
textArea . setForeground ( Color . GREEN );
final Container container = getContentPane ();
container . setLayout ( new GridLayout ( 1 , 1 ));
container . add ( textArea );
setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE );
setSize ( 350 , 400 );
setResizable ( false );
setLocationRelativeTo ( null );
setVisible ( true );
}
public void startPing () {
for ( final String host : listIP ) {
ping ( host );
}
}
private void ping ( final String host ) {
try {
if ( InetAddress . getByName ( host ). isReachable ( 3000 )) {
textArea . append ( "SUCESSO: " + host + "\n" );
} else {
textArea . append ( "FALHA: " + host + "\n" );
}
} catch ( final IOException e ) {
textArea . append ( "ERRO\n" );
}
}
public static void main ( String [] args ) {
final List < String > listIP = new ArrayList < String > ();
listIP . add ( "10.1.1.2" );
listIP . add ( "10.13.101.77" );
listIP . add ( "10.13.101.64" );
listIP . add ( "10.1.1.2" );
listIP . add ( "10.13.101.77" );
listIP . add ( "10.13.101.64" );
IP app = new IP ( listIP );
app . startPing ();
}
}
r063rio 30 de ago. de 2009
Seria isso se nao tivesse apresentando a mensagem “falha” em todos os pings…
valeu…
wesley 31 de ago. de 2009
Mas isso é uma coisa bem óbvia neh… add algum IP conhecido aí …
r063rio 31 de ago. de 2009
Claro que eu ja testei com IP válidos(por exemplo, da internet e da minha rede local), porém, só consegue pingar em 127.0.0.1.
lauronolasco 31 de ago. de 2009
se vc so consegue ‘pingar’ no localhost… algum problema existe na sua rede hein…
uma dica…:
para descer automaticamente a scrollbar em um jtextarea, use:
jtextarea.append("texto");
jtextarea.setCaretPosition(jtextarea.getText().length());
r063rio 31 de ago. de 2009
Wesley, seu código parece está correto. Testei no meu trabalho e respondeu normalmente. Só não entendo pq não pinga em minha casa, no micro conectado no meu HUB, ou em endereços da internet.
Minha rede ta ok…os pings no DOS respondem normalmente.
Era isso. Valeu.