Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

list all machine name and ip addresses in LAN using java

 
karthick chinnathambi
Ranch Hand
Posts: 196
Android Java
  • Mark post as helpful
  • send pies
  • 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....
 
Jason Irwin
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried so far?

And I really don't think this is the right forum.....
 
simran gaur
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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???
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic