This content has been marked as final. Show 6 replies
First you would have to tell us exactly what you mean by "doesn't work".
Hi, thankyou for the reply...
So the problem is that the ping doesn't work.
for example the address 192.168.1.1 is reacable (if I go on the terminal and I ping it it respond) but from my programm the "ping" doesn't work and the method isReacable() return false for all ip.
I hope that now the problem is more clear...
Since no one can help me with the previous question and previous idea (using ping to know if an ip has an host and so if the ip is assigned to a pc)...
I have found another solution.
I try to explain the idea.
So: We use ARP request on the ethernet broadcast address (ff:ff:ff:ff and ip 255.255.255.255).
To do that we make an ARP packet containing: [ our IP | our MAC address ; IP we want to know if is up | FF:FF:FF:FF ] and then we put it into an
ethernet frame with : [our MAC ; FF:FF:FF:FF] and we send it.
If we do this for all subrange ip ( that is for example : 188.8.131.52 ....184.108.40.206) we will receive ARP response of the "ip" (computer) that are connected to the network.
So we can make a list with all pc (ip and MAC) that are connected to our subnet.
I hope this will help.
I wait for some feedback...
If you think that this is a good / bad idea please tell me...
I'm new to network programming and I want to learn and know if I'm on the right way...
the method isReachable() return false for all ip.That doesn't happen when I run it. I get the same reachable hosts that I can see in my ARP table (arp -a).
Re your MAC address/ARP idea, you can't send ARP packets directly from Java.
Why do you need to do this at all? It's an unusual requirement.
I don't know way is reachable for me return false for every ip... I mean if there is such method in Java it's clear that must work... no idea... :-(
For the ARP i don't see what you mean by : you can't send ARP packets directly from Java... I actually use Jpcap library to send ARP packets.
And finally I can say why I need this...
1) I want to practice java programming (since I'm not an expert)
2) I'm interested on network and how it work
3) the program I want to create is a simple network scanner; I mean I want to find all host that are connected to my router...This can be useful to detect intrusion...If some host try to connect to my subnet then the java program (that is listening) detect a new host and can send an alert !
Thank you for the reply...
can you post an example of the usage of isReacable().
For the ARP i don't see what you mean by : you can't send ARP packets directly from Java... I actually use Jpcap library to send ARP packets.That's what I mean. You can't do it from Java. You have to add something.
This can be useful to detect intrusion...If some host try to connect to my subnet then the java program (that is listening) detect a new host and can send an alert !A new host which magically has the correct subnet:IP address? and that is magically plugged in to your router? That would be a fairly major physical intrusion. You don't want to write software for that sort of thing, you want locks on your doors. Security cameras. Access cards, etc.
can you post an example of the usage of isReachable().Why? Your code works for me.