日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/15 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获得主机域名及其IP和Port端口 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

主程序代碼:

?

? ?// 由主機域名獲得其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

轉載于:https://www.cnblogs.com/wdpp/archive/2010/01/24/2387010.html

總結

以上是生活随笔為你收集整理的获得主机域名及其IP和Port端口的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。