資源簡介
獲得主機(jī)域名及其IP和Port端口(初步入門)

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Web;
using?System.Web.UI;
using?System.Web.UI.WebControls;
using?System.Net;
public?partial?class?_Default?:?System.Web.UI.Page
{
????protected?void?Page_Load(object?sender?EventArgs?e)
????{
????????txtaShowAnswer.Value?=?““;
????}
????//?由主機(jī)域名獲得其IP地址
????protected?void?btnShowLocal_Click(object?sender?EventArgs?e)
????{
????????txtaShowAnswer.Value?=?““;
????????string?strShowAnwser?=?string.Empty;
????????string?strHostName?=?Dns.GetHostName();?//獲取本地主機(jī)名
????????strShowAnwser?=?“The?local?host‘s?name?is:?“?+?strHostName?+?“\n“;
????????IPHostEntry?ipHost?=?Dns.GetHostEntry(strHostName);?//將主機(jī)名解析成IPHostEntry實(shí)例
????????foreach?(IPAddress?ip?in?ipHost.AddressList)?//將主機(jī)名(域名)對應(yīng)的IP全部解析出來
????????????strShowAnwser?+=?“The?local?host‘s?IP?is:?“?+?ip.ToString()?+?“\n“;
????????IPAddress?LocalIP?=?IPAddress.Parse(“127.0.0.1“);?//將字符串實(shí)例成IP地址
????????IPEndPoint?ipEP?=?new?IPEndPoint(LocalIP?80);?//將網(wǎng)絡(luò)端點(diǎn)表示成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;
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1074??2010-01-24?21:13??Ip2Url\Default.aspx
?????文件???????1678??2010-01-24?21:14??Ip2Url\Default.aspx.cs
?????文件???????1489??2010-01-24?16:45??Ip2Url\Ip2Url.sln
????..A..H.??????8704??2010-01-24?21:18??Ip2Url\Ip2Url.suo
?????文件???????8682??2010-01-24?16:10??Ip2Url\web.config
?????目錄??????????0??2010-01-24?16:10??Ip2Url\App_Data
?????目錄??????????0??2010-01-24?21:14??Ip2Url
-----------?---------??----------?-----??----
????????????????21627????????????????????7
評論
共有 條評論