简体   繁体   English

如何使用java获取连接到LAN的所有系统名称?

[英]how to get all the system names connected to LAN using java?

I want to get all the systems connected in a LAN? 我希望在局域网中连接所有系统? Can anyone suggest me? 谁能建议我?

The Package I used in Java to achieve this was called jcifs. 我在Java中用来实现这个的包称为jcifs。 Here is the link to the Library . 这是图书馆的链接。

Please note, to identify a machine on a subnet you will need to ping all the avaliable Ip addresses on the subnet. 请注意,要识别子网上的计算机,您需要ping子网上所有可用的IP地址。 From there you can do a reverse IP Address lookup to get the machines details. 从那里,您可以执行反向IP地址查找以获取计算机详细信息。

From memory from the OSI the reason why you want to ping all the machines on the network is because ICMP is still the lowest layer on the OSI Model. 从OSI的内存中,您想要ping网络上所有计算机的原因是因为ICMP仍然是OSI模型上的最低层。 Though you just cannot trust just using ICMP (ping) requests to all machines on the subnet. 虽然您只是不相信对子网上的所有计算机使用ICMP(ping)请求。 The reason for this is most Windows Machines to prevent fishing attacks will block that protocol. 这样做的原因是大多数Windows机器防止钓鱼攻击会阻止该协议。 So instead, you need to take a two stage detection approach. 因此,您需要采用两阶段检测方法。 First, broadcast over the SubNet Ip address with a ICMP ping request. 首先,使用ICMP ping请求通过SubNet IP地址进行广播。 From the ICMP ping request after waiting 1 second, proceed to perform a SMB connection to the non responding IP addresses. 等待1秒后,从ICMP ping请求继续执行与非响应IP地址的SMB连接。 You will find that most people will have either a shared printer of Microsoft Network that will respond to a request under that port. 你会发现大多数人都会有一个Microsoft Network的共享打印机,它将响应该端口下的请求。

The alternative is to use a NetBios reverse name lookup, though it still involves spamming the IP address range of the subnet. 另一种方法是使用NetBios反向名称查找,但它仍然涉及垃圾邮件子网的IP地址范围。

Hope this helps. 希望这可以帮助。

Why do you want them, and why must they be names? 你为什么想要它们,为什么它们必须是名字? Not all systems have a name. 并非所有系统都有名称。

What kind of systems are you trying to enumerate? 您想要枚举什么样的系统?

If you're trying to locate nearby instances of your own application, use multicast UDP to create a discovery protocol. 如果您尝试查找自己应用程序的附近实例,请使用多播UDP创建发现协议。

If you're trying to locate some server which has its own protocol for that purpose, then use its one. 如果您正在尝试找到某个具有自己的协议的服务器,那么请使用它。

If I was going to try to implement this in Java, I'd pick some unused TCP/IP port number and then try to open a socket to each IP address in the LAN's IP address range(s). 如果我打算尝试用Java实现它,我会选择一些未使用的TCP / IP端口号,然后尝试打开一个套接字到LAN的IP地址范围内的每个IP地址。 You expect all the connection attempts to fail, but they should fail in different ways depending on the whether a machine is using the IP address. 您希望所有连接尝试都失败,但它们应以不同方式失败,具体取决于计算机是否使用IP地址。 If an IP address is in use, you should get a "connection refused". 如果正在使用IP地址,则应该“拒绝连接”。 If it is not in use, you should get a "no route to host" or "no route to network". 如果它没有被使用,你应该得到“无主机路由”或“没有网络路由”。 A "connect timed out" may indicate that the host is fire-walled, or that was recently alive but is not alive at the moment. “连接超时”可以指示主机是防火墙的,或者是最近活着但当前不活着的主机。

Another approach (which I don't know is you can do from Java) is to send ARP requests for each of the IP addresses in the network address range and see what turns up in your machine's ARP cache. 另一种方法(我不知道你可以用Java做)是为网络地址范围内的每个IP地址发送ARP请求,看看机器的ARP缓存中出现了什么。

And of course, you can try sending ICMP Ping messages, but they may be firewalled. 当然,您可以尝试发送ICMP Ping消息,但它们可能是防火墙的。

Once you have a list of live IP addresses, use DNS reverse lookup to find the corresponding DNS names. 获得实时IP地址列表后,使用DNS反向查找来查找相应的DNS名称。 But beware that not all IP addresses are bound to DNS names. 但请注意,并非所有IP地址都绑定到DNS名称。

However this is all a bit tenuous given that a lot of machines and networks use firewalls of various kinds, and these are wont to drop network messages or send misleading responses. 然而,鉴于很多机器和网络都使用各种防火墙,这些都不会丢弃网络消息或发送误导性的响应,这一点都有点脆弱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM