C#网络编程学习_01

参考 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";

            }

        }



      



    }

}
QQ截图20140728152935 QQ截图20140728152947 QQ截图20140728152953

你可能感兴趣的:(网络编程)