La mia LAN è composta da:
stampante: 192.168.1.100
pc-mac: 192.168.1.101
pc-win: 192.168.1.102
router: 192.168.1.254
Questa procedura che mi dovrebbe listare tutti gli ip sopra indicati in una jlist:
Codice:
public void listIP(){
try
{
InetAddress address;
DefaultListModel iplan = new DefaultListModel();
jList1.setModel(iplan);
InetAddress localhost = InetAddress.getLocalHost();
iplan.addElement(localhost.getHostAddress());
String ip;
ip = localhost.getHostAddress();
String currIP;
for (int i = 0; i < 256; i++)
{
try
{
currIP = ip.substring(0,ip.length()-3)+String.valueOf(i);
address = InetAddress.getByName(currIP);
if (address.isReachable(5))
{
iplan.addElement(address.getHostAddress());
}
}
catch (IOException e) {
msgbox(ex.getMessage);
}
}
msgbox("Fine ricerca!");
}
catch (UnknownHostException ex) {
msgbox(ex.getMessage());
}
mi produce in output solo:
Codice:
192.168.1.100
192.168.1.101
quando invece gli altri due IP sono pingabili:
Codice:
ping -t 3 192.168.1.102
PING 192.168.1.102 (192.168.1.102): 56 data bytes
64 bytes from 192.168.1.102: icmp_seq=0 ttl=128 time=2.936 ms
64 bytes from 192.168.1.102: icmp_seq=1 ttl=128 time=11.346 ms
64 bytes from 192.168.1.102: icmp_seq=2 ttl=128 time=2.913 ms
--- 192.168.1.102 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 2.913/5.732/11.346/3.970 ms
e
Codice:
ping -t 3 192.168.1.254
PING 192.168.1.254 (192.168.1.254): 56 data bytes
64 bytes from 192.168.1.254: icmp_seq=0 ttl=254 time=2.094 ms
64 bytes from 192.168.1.254: icmp_seq=1 ttl=254 time=2.316 ms
64 bytes from 192.168.1.254: icmp_seq=2 ttl=254 time=2.228 ms
--- 192.168.1.254 ping statistics ---
4 packets transmitted, 3 packets received, 25.0% packet loss
round-trip min/avg/max/stddev = 2.094/2.213/2.316/0.091 ms
Come mai?
In cosa sbaglio?