示例#1
0
    /**
    <summary>Returns an array of all the IPAddresses of the local machine.
    Manually add loopback sense Windows does not have a loopback interface.
    </summary>
    <returns>An array of IPAddresses of the local machine.</returns>
     */
    public static IPAddress[] GetLocalIPAddresses() {
      IPAddress[] base_addresses = null;
      try {
        base_addresses = Dns.GetHostAddresses(string.Empty);
      } catch {
        base_addresses = new IPAddress[0];
      }

      IPAddress[] addresses = new IPAddress[base_addresses.Length + 1];
      base_addresses.CopyTo(addresses, 0);
      addresses[addresses.Length - 1] = IPAddress.Loopback;
      return addresses;
    }