List the IP Address of all computers connected to a single LAN

后端 未结 5 2119
[愿得一人]
[愿得一人] 2020-12-03 11:57

I am writing a program where you connect, for various reasons, to other computers in a LAN. However, rather than having to input the IP address for multiple computers (a pai

相关标签:
5条回答
  • 2020-12-03 12:32

    Can you just look at the IP and subnet mask on the network adapter and ping every address? Whichever ones respond can be queried to see if it has whatever you need to connect.

    0 讨论(0)
  • 2020-12-03 12:47

    Any host discovery tool can help you here. In particular Nmap will certainly give you this information although it might be overkill in this situation. Google for "ping scan" and you should get some useful results.

    0 讨论(0)
  • 2020-12-03 12:50

    You're not really going to find anything more reliable than pinging or arpinging addresses on the same subset. I implemented this for a certain piece of software back in the day on my first internship and, last time I checked (to be fair it was several years ago), that is what they were still using for this functionality. I take that to mean that they haven't found anything better.

    It is not hard to find the source code for these and translate them to C#. ping, arping. Alternatively, you just shell out to a command prompt and execute ping and then parse the results.

    0 讨论(0)
  • 2020-12-03 12:51

    1) Read the subnet mask and calculate all the IP addresses in the subnet mask you are in. Then you can either user ICMP ping (standard ping) or ARP ping to list all the valid IP addresses. ARP Ping is much reliable in a subnet setting.

    2) You can nmap to list all the hosts

    nmap -nsP 192.168.10.1/254 | grep ^Host
    
    0 讨论(0)
  • 2020-12-03 12:53

    See WNetOpenEnum() and WNetEnumResource(), here.

    0 讨论(0)
提交回复
热议问题