2011-01-24 560 views

回答

18

看一看這樣的:link

這:link

textBox1.Text = "Computer Name: " + Environment.MachineName 

textBox2.Text = "IP Add: " + Dns.GetHostAddresses(Environment.MachineName)[0].ToString(); 
+0

謝謝。它工作得很好 – Holyoxx 2011-01-24 05:26:22

3

檢查詳細瞭解此:How To Get IP Address Of A Machine

System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal; 


string strName = p.Identity.Name; 


To get the machine name, 


System.Environment.MachineName 
or 
using System.Net; 
strHostName = DNS.GetHostName(); 


// Then using host name, get the IP address list.. 
IPHostEntry ipEntry = DNS.GetHostByName (strHostName); 
IPAddress [] addr = ipEntry.AddressList; 

for (int i = 0; i < addr.Length; i++) 
{ 
Console.WriteLine ("IP Address {0}: {1} ", i, addr[i].ToString()); 
} 
0

在簡單的方法..

string IP_Address = Dns.GetHostByName(Environment.MachineName).AddressList[0].toString(); 
相關問題