0

I am working on a java server-client app that transfers file btw each oda within a wired or wireless LAN, my problem now is how to detect the IP address of the client computer and the server computer in a wireless or wired LAN. Bottom-line: how to i use java code to detect the ip address of a computer in a wired or wireless LAN connection btw two computers.

  • 1
    Have you seen the related questions? http://stackoverflow.com/questions/2845279/, http://stackoverflow.com/questions/8083479/ – Jason Plank Jan 11 '12 at 12:04

2 Answers2

0
import java.io.*;
import java.net.*;
import java.util.*; 
import static java.lang.System.out;

public class ListNets {

public static void main(String args[]) throws SocketException, UnknownHostException {
     System.out.println(System.getProperty("os.name"));
     Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
    for (NetworkInterface netint : Collections.list(nets))
        if (netint.getName().equals("wlan0") || netint.getName().equals("en0")) {
             displayInterfaceInformation(netint);
        }       
}

static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
    out.printf("Display name: %s\n", netint.getDisplayName());
    out.printf("Name: %s\n", netint.getName());
    Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
    for (InetAddress inetAddress : Collections.list(inetAddresses)) {

        out.printf("InetAddress: %s\n", inetAddress);
    }
    out.printf("\n");
 }
}  
Thirumal
  • 8,280
  • 11
  • 53
  • 103
0

Maybe jgroups can help you: http://www.jgroups.org

Andreas
  • 1,183
  • 1
  • 11
  • 24