前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >获得主机域名及其IP和Port端口

获得主机域名及其IP和Port端口

作者头像
阳光岛主
发布2019-02-19 12:50:22
7.9K1
发布2019-02-19 12:50:22
举报
文章被收录于专栏:米扑专栏米扑专栏米扑专栏

主程序代码:

   // 由主机域名获得其IP地址     protected void btnShowLocal_Click(object sender, EventArgs e)     {         txtaShowAnswer.Value = "";         string strShowAnwser = string.Empty;

        string strHostName = Dns.GetHostName(); //获取本地主机名         strShowAnwser = "The local host's name is: " + strHostName + "/n";         IPHostEntry ipHost = Dns.GetHostEntry(strHostName); //将主机名解析成IPHostEntry实例         foreach (IPAddress ip in ipHost.AddressList) //将主机名(域名)对应的IP全部解析出来             strShowAnwser += "The local host's IP is: " + ip.ToString() + "/n";         IPAddress LocalIP = IPAddress.Parse("127.0.0.1"); //将字符串实例成IP地址         IPEndPoint ipEP = new IPEndPoint(LocalIP, 80); //将网络端点表示成IP地址和端口号         strShowAnwser += "The IPEndPoint is: " + ipEP.ToString() + "/n";         strShowAnwser += "The Address is: " + ipEP.Address + "/n";         strShowAnwser += "The Port is: " + ipEP.Port + "/n";         strShowAnwser += "The AddressFamily is: " + ipEP.AddressFamily + "/n";         strShowAnwser += "The Max port number is: " + IPEndPoint.MaxPort + "/n";         strShowAnwser += "The Min port number is: " + IPEndPoint.MinPort + "/n";

        txtaShowAnswer.Value = strShowAnwser;     }

运行结果:

The local host's name is: Young The local host's IP is: ::1 The local host's IP is: 210.77.29.132 The IPEndPoint is: 127.0.0.1:80 The Address is: 127.0.0.1 The Port is: 80 The AddressFamily is: InterNetwork The Max port number is: 65535 The Min port number is: 0

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2010年01月24日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档