wood burning stoves 2.0*
The moose likes Java in General and the fly likes list all machine name and ip addresses in LAN using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "list all machine name and ip addresses in LAN using java" Watch "list all machine name and ip addresses in LAN using java" New topic
Author

list all machine name and ip addresses in LAN using java

karthick chinnathambi
Ranch Hand

Joined: Jul 06, 2009
Posts: 196

can anyone please help me to write a java code to get the list of all name and ip address that are online in a lan connection using java.......

it will be more helpful if someone come up with the code....


KARTHICK.C , SCJP6-93%
(Born to Win)
Jason Irwin
Ranch Hand

Joined: Jun 09, 2009
Posts: 327
What have you tried so far?

And I really don't think this is the right forum.....


SCJP6
simran gaur
Greenhorn

Joined: Mar 10, 2009
Posts: 7
hi...i did something similar in my project...actually i wrote a code to get IP's of all the machines on my LAN......but for this you have to run this code on every machine in LAN...
you want something like this???
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
Read a bit about nmap. It is doing what you need to do plus a ton more. nmap is written in C(if I remember right) and many of the scans use raw sockets, but some do not, and these can be easily replicated with the Socket class. I am not sure how detailed you need to be, but just to get IP addresses that exist in the LAN, you shouldn't need to use raw sockets, but there are third party libraries to help with that. Ping scans can be useful but don't always work, but a plain old three way handshake is generally pretty good if you don't have a testy firewall to deal with.

A good starting place is to read a description of the default nmap scan, what it is doing and understand basic addressing, subnet masking and/or CIDR. With this you should be able to pull out a good algorithm to build your program from.

If you are having problems getting something to work or don't understand networks, the Sockets and Internet Protocol forum is the appropriate place to ask them.


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

One way is to brute-force check all addresses. For instance:
This will be work as long as your LAN is using just one single subnet. If it isn't then it's going to be a bit harder.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
karthick chinnathambi
Ranch Hand

Joined: Jul 06, 2009
Posts: 196

thanks friends for all your replies......
this is what i expexted........

thanks a lot!!!
karthick chinnathambi
Ranch Hand

Joined: Jul 06, 2009
Posts: 196

simran gaur wrote:hi...i did something similar in my project...actually i wrote a code to get IP's of all the machines on my LAN......but for this you have to run this code on every machine in LAN...
you want something like this???


yes dude exactly the same....
please help me out.....
simran gaur
Greenhorn

Joined: Mar 10, 2009
Posts: 7
ok for this..first of all get your own IP address using InetAddress class.....
e.g


now use spmething like below to get ip's of all the other machines on that LAN...




every machine receiving this container containing a string "hello " will read it and send back a response to machine n.....but this code can only check for 255 machines.....


simran gaur
Greenhorn

Joined: Mar 10, 2009
Posts: 7
actually rob has given you the solution........i used the same approach.......
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
Placing a small server on each machine is not a very flexible or secure solution.
karthick chinnathambi
Ranch Hand

Joined: Jul 06, 2009
Posts: 196

simran gaur wrote:actually rob has given you the solution........i used the same approach.......


thanks friends.......
you guys are really helping me a lot...........
karthick chinnathambi
Ranch Hand

Joined: Jul 06, 2009
Posts: 196

Rusty Shackleford wrote:Placing a small server on each machine is not a very flexible or secure solution.


ya i will try some new ideas and then come up with questions........

if you hav any please share....
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
I already suggested something, it involves mimicking the most basic of the nmap scans. Unless a firewall is dropping all packets(stealth) it will find out if a machine is running at a certain IP address without being dependent on whether or not something is installed remotely.
karthick chinnathambi
Ranch Hand

Joined: Jul 06, 2009
Posts: 196

Rusty Shackleford wrote:I already suggested something, it involves mimicking the most basic of the nmap scans. Unless a firewall is dropping all packets(stealth) it will find out if a machine is running at a certain IP address without being dependent on whether or not something is installed remotely.


ya i saw it....
thanks a lot..........
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
Rob Prime had the beginnings of a simple solution. IIRC, you can you InetAddress to see if you can get ICMP responses, ie ping. Of course this depends on if the target address has a machine that doesn't block ICMP.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

I'm not sure if InetAddress uses ICMP that much. It may use ICMP for the isReachable methods (the Javadoc says it probably will), but it uses simple DNS lookups to resolve the hostname / IP address.

I just tried it with a computer on my network that could not be pinged; it could resolve the IP address just perfectly.
 
jQuery in Action, 2nd edition
 
subject: list all machine name and ip addresses in LAN using java