Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

list all machine name and ip addresses in LAN using java

 
Ranch Hand
Posts: 196
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you tried so far?

And I really don't think this is the right forum.....
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22154
117
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
karthick chinnathambi
Ranch Hand
Posts: 196
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks friends for all your replies......
this is what i expexted........

thanks a lot!!!
 
karthick chinnathambi
Ranch Hand
Posts: 196
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually rob has given you the solution........i used the same approach.......
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Placing a small server on each machine is not a very flexible or secure solution.
 
karthick chinnathambi
Ranch Hand
Posts: 196
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 196
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 196
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22154
117
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic