.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="轉(zhuǎn)化為域名"></asp:button>
    <asp:label id="label2" runat="server"></asp:label>
    <asp:button id="button1" runat="server"
     text="轉(zhuǎn)化為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)
  {//轉(zhuǎn)化為ip地址
   iphostentry hostinfo=dns.gethostbyname(textbox1.text);
   label2.text=hostinfo.addresslist[0].tostring();
  }
  private void button2_click(object sender, system.eventargs e)
  {//轉(zhuǎn)化為域名
   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();
  }
新聞熱點
疑難解答
圖片精選