title: How to get the Local IP-Broadcast Address dynamically C#
body: <p>My first Problem was, <a href="https://stackoverflow.com/questions/25259100/c-sharp-udp-chat-receive-no-message">C# UDP Chat receive no message</a>, one atempt to fix this was to avoid.</p>
  
  <pre><code>IPAddress.Broadcast
  </code></pre>
  
  <p>So i wrote a function to  determine the local broadcast:</p>
  
  <pre><code>    private IPAddress get_broadcast()
      {
          try
          {
              string ipadress;
              IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName()); // get a list of all local IPs
              IPAddress localIpAddress = ipHostInfo.AddressList[0]; // choose the first of the list
              ipadress = Convert.ToString(localIpAddress); // convert to string
              ipadress = ipadress.Substring(0, ipadress.LastIndexOf(".")+1); // cuts of the last octet of the given IP 
              ipadress += "255"; // adds 255 witch represents the local broadcast
              return IPAddress.Parse(ipadress); 
          }
          catch (Exception e)
          {
              errorHandler(e);
              return IPAddress.Parse("127.0.0.1");// in case of error return the local loopback
          }
      }
  </code></pre>
  
  <p>but this only works on /24 Networks I often switch between /24(at home) and /16(at work) networks. So a hard coded subnetmask don't fit my requirements.</p>
  
  <p>so, is there any good way to determine the local broadcast without using "IPAddress.Broadcast"?</p>