how to scan neighboring device IP's using java?
hello,
how to scan neighboring device IP's using java like IP scanner.
is it possible?.
I need to scan available devices in my network range and show their IP addresses in separate table.
is it possible?
[235 byte] By [
rameshsa] at [2007-11-27 11:11:56]

# 1
1. Most important. Get permission in writing from either your supervisor or the network owner to run the software on any network where you personally will be running it. People have been fired, expelled, civilly and criminally prosecuted for doing this.
2. Determine what a range is. This is easiest as a config parameter and probably the only correct way.
3. Decide what exactly 'scanning' means. Sometimes pinging is sufficient sometimes it isn't.
4. Verify that you really one active boxes and not a list of all devices. The second requires a manual list rather than anything programmatic.
5. Create a list of specific address from the range.
6. Scan each one (ping it if that is sufficient.)
7. Collect failures/success and do what ever you want.
# 2
> (ping it if that is sufficient.)
Which cannot be done with pure Java, and rarely brings a correct result.
# 4
and that will help how?
ejpa at 2007-7-29 13:51:21 >

# 5
i thought over
wat i concluded is this
make 2 programs
a server that runs on each pc in the network
a client that sends datagram packet when invoked
those servers that receive reply back(servers r always open to recieve)
and we built a list for all those who replied back showing their ip addresses
# 6
> > (ping it if that is sufficient.)
>
> Which cannot be done with pure Java, and rarely
> brings a correct result.
Yes it can be done with "pure" java.
It certainly returns a result.
As to whether that is sufficient or not depends on the actual requirements. Although in my experience I haven't particularly found it sufficient myself but I have never been satisfied with other solutions either.
# 7
but i think that to make a application you have to go for datagrams
# 8
try
{
new datagramthread();
ServerSocket ss=new ServerSocket(3030);
for(;;)
{
Socket incoming=ss.accept();
new ThreadHandler(incoming);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
static class ThreadHandler extends Thread
{
Thread t;
public Socket incoming;
PrintWriter douta;
public ThreadHandler(Socket i) throws IOException
{
incoming=i;
like this u can make a server
public static class multidatagram
{
public multidatagram()throws IOException
{
Vector servers=new Vector();
DatagramSocket socket=new DatagramSocket();
socket.setSoTimeout(3000);
try
{
byte[]buf=new byte[256];
InetAddress group =InetAddress.getByName("230.0.0.1");
DatagramPacket packet=new DatagramPacket(buf,buf.length,group,4601);
socket.send(packet);
while(true)
{
packet =new DatagramPacket(buf,buf.length);
socket.receive(packet);
InetAddress i= packet.getAddress();
String name=i.getHostName();
servers.addElement(name);
}
}
and with this idea u make a client
now what else
# 9
> but i think that to make a application you have to go
> for datagrams
Huh?
You can make an application do anything.
And you can decide to test that application, via the network, using any of a variety of methods. Datagrams are not required and are not likely to be often part of a solution (in general.)
# 10
ohk just tell me how u make a ipscanner without datagram concept
dont take i am challenging you,just asking.
because i use to think this was the best way
cheers
# 11
> ohk just tell me how u make a ipscanner without
> datagram concept
> dont take i am challenging you,just asking.
> because i use to think this was the best way
First tell me what the requirements or business need is.
For example if you are creating a Network Management System then it is not normally going to be sufficient just to know whether routers, gateways, servers, power supplies, etc exist. You need to know that they are running correctly.
# 12
> Yes it can be done with "pure" java.
>
> It certainly returns a result.
>
How? As far as I know, the only pure Java code that provides a way for doing this is the isReachable() method of the InetAddress class. It does not work with ICMP in the windows implementation. On the linux platform, it only use ICMP if there's enough privilege (root).
Other libraries, are just some native code plugged into Java by the JNI, which are not considered "pure" Java.
It certainly does not return a correct result in all cases, as many computers have installed firewalls which block all ICMP requests.
# 13
> > Yes it can be done with "pure" java.
> >
> > It certainly returns a result.
> >
>
> How? As far as I know, the only pure Java code that
> provides a way for doing this is the isReachable()
> method of the InetAddress class. It does not work
> with ICMP in the windows implementation. On the linux
> platform, it only use ICMP if there's enough
> privilege (root).
>
> Other libraries, are just some native code plugged
> into Java by the JNI, which are not considered "pure"
> Java.
>
> It certainly does not return a correct result in all
> cases, as many computers have installed firewalls
> which block all ICMP requests.
It doesn't return a result if there is no physical connection either.
So it isn't going to work in that case either.
But as I said several times already one really needs actual requirements to make a decision on what the actual implementation needs to be.
# 14
> It doesn't return a result if there is no physical
> connection either.
> So it isn't going to work in that case either.
A device without a working physical link is not considered "available", but a computer with a firewall is. It can be easily accessed by the application. So, pinging does not return a correct result in all cases for finding available neighboring devices. The OP wants to do so.
By the way, please tell me if you succeeded to Ping a host (Sending an ICMP Echo Request) using "pure" Java. It will be highly appreciated.
# 15
> By the way, please tell me if you succeeded to Ping a
> host (Sending an ICMP Echo Request) using "pure"
> Java. It will be highly appreciated.
Appreciated it may be but possible it is not.
# 16
> > It doesn't return a result if there is no physical
> > connection either.
> > So it isn't going to work in that case either.
>
> A device without a working physical link is not
> considered "available", but a computer with a
> firewall is. It can be easily accessed by the
> application.
Not easily at all if the access is disallowed.
> So, pinging does not return a correct
> result in all cases for finding available neighboring
> devices. The OP wants to do so.
I suggest you read my response again, because my response included far more than that. And I have repeated the main point several times as well.
>
> By the way, please tell me if you succeeded to Ping a
> host (Sending an ICMP Echo Request) using "pure"
> Java. It will be highly appreciated.
Curious - are you claiming that there is no Java API in the world that actually uses ICMP for the IsReachable() method?
Or just that none of the implementations work under any circumstances at all?
And when you said in reply #2 "rarely brings a correct result." you really meant to say never?
# 17
> Curious - are you claiming that there is no Java API in the world that actually uses ICMP for the IsReachable() method?
The ICMP code is commented out in all versions of the source code I've ever seen.
ejpa at 2007-7-29 13:51:26 >

# 18
> > Curious - are you claiming that there is no Java
> API in the world that actually uses ICMP for the
> IsReachable() method?
>
> The ICMP code is commented out in all versions of the
> source code I've ever seen.
So would that include the IBM, Weblogic, Macintosh, HP, AIX, etc versions?
If yes then there should probably be a bug opened on the Java API docs.
If not then perhaps we could just go back to my original response which suggested that requirements and not technology should drive the determination of what method to use.
# 19
I agree completely with your last part, but using ICMP on any Unix/Linux/AIX system requires root privilege, as another poster has already stated, so, regardless of what is or isn't in the source code, it is vanishingly unlikely that any Java implementation anywhere is actually executing pings via ICMP to any significant extent.
Not that I've ever come across a legitimate requirement to do so.
ejpa at 2007-7-29 13:51:26 >

# 20
> It is vanishingly unlikely that any Java implementation
> anywhere is actually executing pings via ICMP
> to any significant extent.
And a simple low-level network monitoring shows that in all versions, Windows implementation has nothing to do with ICMP at all.
Also, all third party APIs to do ICMP in Java, as I already mentioned, are just native codes.
# 21
> If not then perhaps we could just go back to
> my original response which suggested that
> requirements and not technology should
> drive the determination of what method to use.
True.
# 22
> I agree completely with your last part, but using
> ICMP on any Unix/Linux/AIX system requires root
> privilege, as another poster has already stated, so,
> regardless of what is or isn't in the source code, it
> is vanishingly unlikely that any Java implementation
> anywhere is actually executing pings via ICMP
> to any significant extent.
Quite possible.
>
> Not that I've ever come across a legitimate
> requirement to do so.
I agree that it is vanishingly small that using ICMP is actually going to meet the requirements of any monitoring system as well. It certainly wouldn't meet those of any NMS/EMS system.
It would not have been even close to sufficient to anything that I have worked on.
# 23
> is vanishingly unlikely that any Java implementation
> anywhere is actually executing pings via ICMP
> to any significant extent.
>
> Not that I've ever come across a legitimate
> requirement to do so.
That's my highest priority project right now. It's going to run on windows so I'll have to use JNI, obviously.
jverda at 2007-7-29 13:51:26 >
