Computers on LAN

How can I find out the list of computers connected to a LAN using java.net package ?
[98 byte] By [pbp76a] at [2007-10-2 21:18:46]
# 1
No way. Using java or using anything else. Except checking each cable :)
Michael.Nazarov@sun.coma at 2007-7-14 0:27:47 > top of Java-index,Java Essentials,Java Programming...
# 2
I think my question was not formed well. Sorry for that.I need to have hostnames/ IP addresses of each computer connected to a particular LAN.
pbp76a at 2007-7-14 0:27:48 > top of Java-index,Java Essentials,Java Programming...
# 3

No way as well. There are number of tricks to collect some data only. There is no set of actions to perform (using any kind of tools) and get complete list of hosts after.

You can get IP by name or name by IP, but you can't even detect is known host online or offline with 100% guarantee.

Michael.Nazarov@sun.coma at 2007-7-14 0:27:48 > top of Java-index,Java Essentials,Java Programming...
# 4
ping the segment broadcast addresscheck your arp table
tschodta at 2007-7-14 0:27:48 > top of Java-index,Java Essentials,Java Programming...
# 5
And? :)What about hosts with disabled ICMP answers? They will not send aswer to your ping.
Michael.Nazarov@sun.coma at 2007-7-14 0:27:48 > top of Java-index,Java Essentials,Java Programming...
# 6

> I think my question was not formed well. Sorry for

> that.

> I need to have hostnames/ IP addresses of each

> computer connected to a particular LAN.

If i understood your question correctly, you wanted to get list of hosts which are currently connected to your LAN.

In that case (donno whether its correct way) , you can try with

Runtime class and execute "net view" command( in windows).

That should display all computers that are connected in LAN

@a at 2007-7-14 0:27:48 > top of Java-index,Java Essentials,Java Programming...
# 7

in command prompt (cmd -windows):

we should redirect the output to one file.

eg : "c:>net view > newFile.txt"

after that we should read the file .

is there any way to redirect the output or (get the output) of cmd to our java program from running process directly?.

thaniyarasua at 2007-7-14 0:27:48 > top of Java-index,Java Essentials,Java Programming...
# 8
Runtime.exec(), Process.getInputStream(), InputStream.read()
Michael.Nazarov@sun.coma at 2007-7-14 0:27:48 > top of Java-index,Java Essentials,Java Programming...
# 9

> > I think my question was not formed well. Sorry for

> > that.

> > I need to have hostnames/ IP addresses of each

> > computer connected to a particular LAN.

>

> If i understood your question correctly, you wanted

> to get list of hosts which are currently connected to

> your LAN.

> In that case (donno whether its correct way) , you

> can try with

> Runtime class and execute "net view" command( in

> windows).

> That should display all computers that are connected

> in LAN

I believe that shows all windows/samba machines in a domain.

RadcliffePikea at 2007-7-14 0:27:48 > top of Java-index,Java Essentials,Java Programming...
# 10

> In that case (donno whether its correct way) , you

> can try with

> Runtime class and execute "net view" command( in

> windows).

> That should display all computers that are connected

> in LAN

But won't that make the code platform specific?

pbp76a at 2007-7-14 0:27:48 > top of Java-index,Java Essentials,Java Programming...
# 11

> > In that case (donno whether its correct way) , you

> > can try with

> > Runtime class and execute "net view" command( in

> > windows).

> > That should display all computers that are

> connected

> > in LAN

>

>

> But won't that make the code platform specific?

Yes, your right.

Firstly, directly its not possible in java what you want. But there are other alternates which give you temporary results the one which i suggested. If you want to make it work on any platform, then you should know the relevant commands of all platforms that shows the results and have conditional statements.

@a at 2007-7-14 0:27:48 > top of Java-index,Java Essentials,Java Programming...