標籤:style blog http color os 2014 for art
參考http://blog.csdn.net/yuzhongchun/article/details/11990571
using System.Net;namespace Network_01{ public partial class Main : Form { public Main() { InitializeComponent(); } private void btnGetHostName_Click(object sender, EventArgs e) { DebugInfo.Text = Dns.GetHostName();//返回本機名稱 } private void btnGetHostEntry_Click(object sender, EventArgs e) { DebugInfo.Text = ""; IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName()); //返回目標主機執行個體 foreach (IPAddress ipAddr in ipEntry.AddressList) { if (ipAddr.AddressFamily.ToString() == "InterNetwork") //IP4 InterNetworkV6 IP6 DebugInfo.Text += ipAddr.AddressFamily.ToString()+":" + ipAddr.ToString() + "\r\n"; } } private void WebGetHostEntry_Click(object sender, EventArgs e) { DebugInfo.Text = ""; IPHostEntry ipEntry = Dns.GetHostEntry(AddrText.Text.Trim()); foreach (IPAddress ipAddr in ipEntry.AddressList) { if (ipAddr.AddressFamily.ToString() == "InterNetwork") //IP4 DebugInfo.Text += ipAddr.AddressFamily.ToString() + ":" + ipAddr.ToString() + "\r\n"; } } }}