.aspx代码
<form id="form1" method="post" runat="server">
<font face="宋体">
<asp:textbox id="textbox1" runat="server"
width="248px"></asp:textbox>
<asp:button id="button2" runat="server"
text="转化为域名"></asp:button>
<asp:label id="label2" runat="server"></asp:label>
<asp:button id="button1" runat="server"
text="转化为ip"></asp:button>
<asp:label id="label1" runat="server">通过域名获得ip地址</asp:label></font>
</form>
.aspx.cs代码
using system.net;
private void button1_click(object sender, system.eventargs e)
{//转化为ip地址
iphostentry hostinfo=dns.gethostbyname(textbox1.text);
label2.text=hostinfo.addresslist[0].tostring();
}
private void button2_click(object sender, system.eventargs e)
{//转化为域名
iphostentry hostinfo=dns.gethostbyaddress(textbox1.text);
label2.text=hostinfo.hostname;
}
获得主机名和ip地址
private void page_load(object sender, system.eventargs e)
{
// 在此处放置用户代码以初始化页面
dns dns;
string hostname=dns.gethostname();
ipaddress[] ip=dns.resolve(hostname).addresslist;
label2.text="机器名称:"+hostname.tostring()+"<br>ip地址:"+ip[0].tostring();
}
新闻热点
疑难解答
图片精选