How to get a list of IP addresses that are connected to a broadcast IP address using the Udp protocol?

There is such code:

UdpClient _onlineInformer = new UdpClient() { EnableBroadcast = true, Ttl = 1 }; _onlineInformer.Connect("192.168.152.255", 0); 

How can _onlineInformer find out about the connected sockets at the same address?

  • @dima_kot, what do you mean by connecting by Udp to the broadcast IP address ? You probably want to know all the sockets (in the program ?, system?) That can send broadcast UDP packets? As far as I know, for them to receive setsockopt (..., SO_BROADCAST, ...) do not need. - avp
  • Anybody can send broadcasts. I need a list of all addresses connected to the broadcast address. - MaxMax
  • one
    They do not connect to broadcast. If you are listening to the port (made a bind () for the udp socket), then you will read all the packets sent to this port. As sent specifically to this host , and broadcast. At least in * nix. Concerning "Send Broadcast Packages Can Be Everything" - I don’t know, maybe in c # setsockopt (..., SO_BROADCAST ...) is done by default. - avp
  • About "Send broadcasts can all" - I have not clearly articulated. I myself do this in code like EnableBroadcast = true for each socket. And the task comes down to getting a list of sockets that will receive the packet sent to the Broadcast address - MaxMax
  • In the output of the netstat command for UDP protocol in the column 'Local Address' after ':' the port number. In * nix you can run lsof root @ avp-xub11: ~ # lsof -i4UDP COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME avahi-dae 527 avahi 13u IPv4 7150 0t0 UDP * dae 527 avahi 15u IPv4 7152 0t0 UDP *: 46109 rpcbind 539 root 6u IPv4 7200 0t0 UDP *: sunrpc rpcbind 539 root 7u IPv4 7201 0t0 UDP *: 713 .... There is a port in the NAME column. - avp pm

1 answer 1

You can try to ping Broadcast-address, but only those hosts that are allowed to broadcast. If there are routers between them, they should also be allowed to broadcast.

Addition : In your case, you can implement your own lightweight protocol by which other hosts will respond to the polling host.