使用 java 的有线/无线 LAN 中的 IP 地址

发布于 2024-12-26 04:18:58 字数 136 浏览 2 评论 0原文

我正在开发一个java服务器客户端应用程序,它可以在有线或无线局域网内的每个OD之间传输文件,我现在的问题是如何检测无线或有线局域网中客户端计算机和服务器计算机的IP地址。底线:如何使用java代码来检测两台计算机之间有线或无线LAN连接中计算机的IP地址。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青巷忧颜 2025-01-02 04:18:58

也许 jgroups 可以帮助你:http://www.jgroups.org

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

江挽川 2025-01-02 04:18:58
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");
 }
}  
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");
 }
}  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文