Java 获取Wifi网络上设备的名称和IP

Java 获取Wifi网络上设备的名称和IP,java,swing,device,Java,Swing,Device,我知道这里有人问过这个问题,但没有得到回答 我正在编写一个简单的JavaSwing应用程序,其中我想显示连接到无线网络的每个设备的名称和IP地址 我想在JFrame中显示此列表。我在网上搜索了很多,但找不到实现这一目标的方法。请帮我解决Java大师 提前谢谢 我看了一眼后发现了这段代码。它是有效的,但速度很慢,可能不是最好的方法,但它是有效的 import java.io.IOException; import java.net.InetAddress; public class Networ

我知道这里有人问过这个问题,但没有得到回答

我正在编写一个简单的JavaSwing应用程序,其中我想显示连接到无线网络的每个设备的名称和IP地址

我想在
JFrame
中显示此列表。我在网上搜索了很多,但找不到实现这一目标的方法。请帮我解决Java大师


提前谢谢

我看了一眼后发现了这段代码。它是有效的,但速度很慢,可能不是最好的方法,但它是有效的

import java.io.IOException;
import java.net.InetAddress;

public class NetworkPing {

    /**
     * JavaProgrammingForums.com
     */
    public static void main(String[] args) throws IOException {

        InetAddress localhost = InetAddress.getLocalHost();
        // this code assumes IPv4 is used
        byte[] ip = localhost.getAddress();

        for (int i = 1; i <= 254; i++)
        {
            ip[3] = (byte)i;
            InetAddress address = InetAddress.getByAddress(ip);
        if (address.isReachable(1000))
        {
            System.out.println(address + " machine is turned on and can be pinged");
        }
        else if (!address.getHostAddress().equals(address.getHostName()))
        {
            System.out.println(address + " machine is known in a DNS lookup");
        }
        else
        {
            System.out.println(address + " the host address and host name are equal, meaning the host name could not be resolved");
        }
        }

    }
}
import java.io.IOException;
导入java.net.InetAddress;
公共类网络{
/**
*JavaProgrammingForums.com
*/
公共静态void main(字符串[]args)引发IOException{
InetAddress localhost=InetAddress.getLocalHost();
//此代码假定使用了IPv4
字节[]ip=localhost.getAddress();
对于(inti=1;i试试这个:)

import java.io.IOException;
导入java.net。*;
导入java.util.Vector;
公共类搜索{
公共静态void main(字符串args[])引发UnknownHostException{
可用向量_设备=新向量();
字符串myip=InetAddress.getLocalHost().getHostAddress();
字符串mynetworkips=新字符串();
对于(int i=myip.length();i>0;--i){
if(myip.charAt(i-1)='.'){mynetworkips=myip.substring(0,i);break;}
}
System.out.println(“我的设备IP:+myip+”\n”);
System.out.println(“搜索日志:”);

对于(int i=1;我“我知道这里有人问过这个问题,但没有得到回答。”什么问题?提供一个链接。可能因为没有答案而没有回答,再次询问不会改变这一点。感谢您的帮助!我已签出。它显示了IP地址,但没有显示连接设备的名称。
address.getHostName()
只需再次向我显示IP地址。如何获取连接设备的名称?请尝试再次运行,我无法给出它工作的原因,但通常会在第二次运行时工作
import java.io.IOException;
import java.net.*;
import java.util.Vector;

public class search {
    public static void main(String args[]) throws UnknownHostException{

        Vector<String> Available_Devices=new Vector<>();
        String myip=InetAddress.getLocalHost().getHostAddress();
        String mynetworkips=new String();

        for(int i=myip.length();i>0;--i) {
            if(myip.charAt(i-1)=='.'){ mynetworkips=myip.substring(0,i); break; }
        }

        System.out.println("My Device IP: " + myip+"\n");

        System.out.println("Search log:");
        for(int i=1;i<=254;++i){
            try {
                InetAddress addr=InetAddress.getByName(mynetworkips + new Integer(i).toString());
                if (addr.isReachable(1000)){
                    System.out.println("Available: " + addr.getHostAddress());
                    Available_Devices.add(addr.getHostAddress());
                }
                else System.out.println("Not available: "+ addr.getHostAddress());

            }catch (IOException ioex){}
        }

        System.out.println("\nAll Connected devices(" + Available_Devices.size() +"):");
        for(int i=0;i<Available_Devices.size();++i) System.out.println(Available_Devices.get(i));
    }
}