isReachable() qual o erro?

0 respostas
S

Alguem pode me explicar o errro nesse codigo? nao entendo e preciso dele pro resto do projeto

import java.net.InetAddress;
import java.util.ArrayList;

public class Ping {

	private ArrayList ip = new ArrayList();
	private ArrayList nome = new ArrayList();
	private boolean[] status;

	public Ping(ArrayList ip, ArrayList nome) {
		this.ip = ip;
		this.nome = nome;
		this.status = new boolean[ip.size()];
		for (int i = 0; i < status.length; i++)
			this.status[i] = true;
		pingar();
	}

	public void pingar() {
		while (true) {
			for (int i = 0; i < ip.size(); i++) {
				try {
					if (InetAddress.getByName((String) ip.get(i)).isReachable(
							5000)) {
						if (status[i] == false) {
							status[i] = true;
							System.out.println(((String)nome.get(i))+" OK");
						}
					} else {
						if (status[i]) {
							status[i] = false;
							System.out.println(((String)nome.get(i))+" OFFLINE");
						}
					}
				} catch (Exception ex) {
					ex.getStackTrace();
					System.out.println(((String)nome.get(i))+" Erro");
				}
			}
		}
	}

	public static void main(String[] args) {
		ArrayList ip = new ArrayList();
		ArrayList nome = new ArrayList();
		
		ip.add("209.85.193.104");
		nome.add("www.google.com.br");
		
		ip.add("200.176.3.142");
		nome.add("www.terra.com.br");
		
		ip.add("200.152.161.132");
		nome.add("www.yahoo.com.br");
		
		ip.add("200.200.20.4");
		nome.add("nao existe e nao funciona aki");
				
		Ping p = new Ping(nome, ip);		
	}
}

ele da tudo offline, da sempre erro, oque fiz de errado
tipo, eu sei que normalmente se usa o getByAddress(byte[])
so que o byte aceita so ate 127, entao n daria certo, como posso fazer, preciso testar com ping, n tem jeito

Criado 20 de setembro de 2008
Respostas 0
Participantes 1