title: Get the server name and ip address in C# 2010
body: <p>Get the server name and ip address in C# 2010</p>
  
  <p>I want to get the IP address of the server. The following code comes from:</p>
  
  <pre><code>public static void DoGetHostEntry(string hostname)
  {
  
          IPHostEntry host;
  
          host = Dns.GetHostEntry(hostname);
  
          MessageBox.Show("GetHostEntry({0}) returns:"+ hostname);
  
          foreach (IPAddress ip in host.AddressList)
          {
              MessageBox.Show("    {0}"+ ip.ToString());
          }
  }
  </code></pre>
  
  <p>This code must know the name of the server computer.<br>
  AddressFamily in System.Net.IPAddress<br></p>
  
  <p><code>System.Net.IPAddress i;</code><br>
  <code>string HostName = i.AddressFamily.ToString();</code></p>
  
  <p>Error ------------->Use of unassigned local variable 'i'</p>
  
  <p>How can I get the name of the server computer?</p>