<tt>obtaining ip addresses</tt>
2 posts in topic
Flat View  Flat View

Posted By:   Crystal_Huang
Posted On:   Monday, July 23, 2001 08:19 PM

How can I write a program which will obtain the IP addresses of each and every machine connected to the LAN?

Re: obtaining ip addresses

Posted By:   Aravind_Thangaraj  
Posted On:   Monday, December 1, 2003 10:13 PM

try this code... in JDK 1.4

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class Addrs {
public static void main(String[] args) throws SocketException {
Enumeration ifaces = NetworkInterface.getNetworkInterfaces();

while (ifaces.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface)ifaces.nextElement();
System.out.println(ni.getName() + ":");

Enumeration addrs = ni.getInetAddresses();

while (addrs.hasMoreElements()) {
InetAddress ia = (InetAddress)addrs.nextElement();
System.out.println(" " + ia.getHostAddress());

Hope this will help you..
Good day

Re: obtaining ip addresses

Posted By:   Scott_McCrory  
Posted On:   Wednesday, October 24, 2001 09:43 PM

Network management programs like Tivoli, OpenView, ManageIT, etc. typically either put the NIC into "promiscuous mode" and listen for some time for all traffic on the segment, OR they ping-scan a range of addresses you specify to see who responds. The first method only works up to your segment's gateway router and requires low-level hardware access, which Java typically does not have. The second approach is easy to do in Java but if your company, university, etc. prohibits scanning then you could get yourself in a bit of trouble. If it's OK to do, then take a look at the java.io section in Java Examples in a Nutshell or search online for "Java ping".
About | Sitemap | Contact