0

I want to find all devices on my local network using c#.

The solutions that have at the moment is based on pinging each ip on my local network. something that explained here:

How to Perform Multiple "Pings" in Parallel using C#

The problem is that if I have more than one network interface on my PC (for example one wifi and one Ethernet) how can I understand which one should I ping? How to find suitable address range for each network? and so on. If the subnet mask is very big (for example when subnet is 255.255.0.0, it would takes a lot of time to do this.

There are some other suggested solution such as this:

Locating computer on subnet/network

But how can I ping the broadcast address and find who is answering? Ping in C# only return one result for one IP (Am I right)?

Is there any better solution?

Community
  • 1
  • 1
mans
  • 17,104
  • 45
  • 172
  • 321
  • suitable addresses = get an interface's IP, get its netmask, and that'll give you the range of IPs that are "local". – Marc B Jun 12 '14 at 15:19
  • @MarcB How to get interface Ip and its mask? How can I enumerate interfaces in my computer? – mans Jun 12 '14 at 15:20
  • Out of curiosity, and maybe to suggest a completely different solution, would you mind telling us what the overall situation is? Why do you want to ping all possible addresses? – RenniePet Jun 12 '14 at 15:22
  • @RenniePet: I am looking for all devices on my local network and find their IP. In this way I can scan them to find if they are the devices that I want. For example assume that I am trying to search for all of my own deign devices in the network. If I know their then I can send a request for ID to the and make sure that they are at that IP. I can send the request to each IP, but it is too time consuming. I prefer a way that I know address and then start search from there. – mans Jun 12 '14 at 15:27
  • I'm not an expert on this, but I think you should look into the Windows Remote Procedure Call facility. My understanding is that client programs (such as Outlook) find the host they want to talk to (Exchange Server) via RPC. This makes use of a naming service, so Exchange tells the RPC system "I'm an Exchange Server, anyone looking for an Exchange Server can talk to me". The Outlook programs say to RPC "Are there any Exchange Servers around, connect me to them if so". This avoids the problems with pinging blindly. – RenniePet Jun 12 '14 at 15:31

1 Answers1

1

"But how can I ping the broadcast address and find who is answering?" There is no such thing as a broadcast ping. If you look at a network scanning tool like nmap, which has a "ping sweep" feature, the way it identifies nodes on the network is through individual pings.

zspath
  • 11
  • 1
  • What about ping to broadcast address? the way that documented here:http://stackoverflow.com/questions/2567107/ping-or-otherwise-tell-if-a-device-is-on-the-network-by-mac-in-c-sharp If can I read ARP, I can find the range of IPs and then send command to get their IP directly. – mans Jun 12 '14 at 15:29