利用DNS类.域名转化ip地址,利用ip地址转换域名

DNS类.internet域名系统是网络应用程序获取网络上主机信息的常规系统.

主机的信息包括主机名,域名,ip地址.

DNS方法总是以IPJostEntry对象的形式返回信息.

cs代码: 

using  System;
using  System.Collections;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Web;
using  System.Web.SessionState;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.HtmlControls;
using  System.Net;
namespace  ASPNETWORK
{
    
/// <summary>
    
/// WebForm1 的摘要说明。
    
/// </summary>

    public partial class WebForm1 : System.Web.UI.Page
    
{
    
        
protected void Page_Load(object sender, System.EventArgs e)
        
{
            lbHost.Text 
= Dns.GetHostName();
            IPHostEntry Host 
= Dns.GetHostByName(lbHost.Text);
            lbHost.Text 
= "本机域名为:"+lbHost.Text+"IP地址为:"+Host.AddressList[0].ToString();
           
        }


        
Web Form Designer generated code

        
protected void btnGetIP_Click(object sender, System.EventArgs e)
        
{
            
try
            
{
                IPHostEntry Host 
= Dns.GetHostByName(tbDomain.Text);
                lbIP.Text 
= Host.AddressList[0].ToString();
            }

            
catch(Exception ex)
            
{
                lbIP.Text 
= ex.Message.ToString();
            }

        }


        
protected void getDomain_Click(object sender, System.EventArgs e)
        
{
            
try
            
{
                IPHostEntry  Host 
= Dns.GetHostByAddress(tbIP.Text);
                lbDomain.Text 
= Host.HostName;
            }

            
catch(Exception ex)
            
{
                lbDomain.Text 
= ex.Message.ToString();
            }

                
        }

    }

}

html代码:  
<% @ Page language="c#" Inherits="ASPNETWORK.WebForm1" CodeFile="01DNS.aspx.cs"  %>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"  >
< HTML >
    
< HEAD >
        
< title > WebForm1 </ title >
        
< meta  name ="GENERATOR"  Content ="Microsoft Visual Studio 7.0" >
        
< meta  name ="CODE_LANGUAGE"  Content ="C#" >
        
< meta  name ="vs_defaultClientScript"  content ="JavaScript" >
        
< meta  name ="vs_targetSchema"  content ="http://schemas.microsoft.com/intellisense/ie5" >
    
</ HEAD >
    
< body >
        
< form  id ="Form1"  method ="post"  runat ="server" >
            
< asp:Label  id ="Label1"  style ="Z-INDEX: 100; LEFT: 242px; POSITION: absolute; TOP: 53px"  runat ="server"  Width ="224px"  Font-Size ="XX-Large" > DNS示例 </ asp:Label >
            
< asp:Label  id ="lbDomain"  style ="Z-INDEX: 113; LEFT: 571px; POSITION: absolute; TOP: 238px"  runat ="server"  Width ="136px" ></ asp:Label >
            
< asp:Button  id ="getDomain"  style ="Z-INDEX: 112; LEFT: 484px; POSITION: absolute; TOP: 236px"  runat ="server"  Text ="得到域名"  onclick ="getDomain_Click" ></ asp:Button >
            
< asp:TextBox  id ="tbIP"  style ="Z-INDEX: 111; LEFT: 297px; POSITION: absolute; TOP: 237px"  runat ="server" ></ asp:TextBox >
            
< asp:Label  id ="Label4"  style ="Z-INDEX: 110; LEFT: 165px; POSITION: absolute; TOP: 243px"  runat ="server" > 请输入IP: </ asp:Label >
            
< asp:TextBox  id ="TextBox1"  style ="Z-INDEX: 103; LEFT: 296px; POSITION: absolute; TOP: 191px"  runat ="server" ></ asp:TextBox >
            
< asp:Button  id ="Button1"  style ="Z-INDEX: 105; LEFT: 484px; POSITION: absolute; TOP: 191px"  runat ="server"  Text ="得到IP" ></ asp:Button >
            
< asp:Label  id ="lbHost"  style ="Z-INDEX: 101; LEFT: 157px; POSITION: absolute; TOP: 136px"  runat ="server"  Width ="459px" ></ asp:Label >
            
< asp:Label  id ="Label2"  style ="Z-INDEX: 102; LEFT: 162px; POSITION: absolute; TOP: 195px"  runat ="server" > 请输入域名: </ asp:Label >
            
< asp:TextBox  id ="tbDomain"  style ="Z-INDEX: 104; LEFT: 296px; POSITION: absolute; TOP: 191px"  runat ="server" ></ asp:TextBox >
            
< asp:Button  id ="btnGetIP"  style ="Z-INDEX: 106; LEFT: 484px; POSITION: absolute; TOP: 191px"  runat ="server"  Text ="得到IP"  onclick ="btnGetIP_Click" ></ asp:Button >
            
< asp:Label  id ="lbIP"  style ="Z-INDEX: 109; LEFT: 574px; POSITION: absolute; TOP: 195px"  runat ="server"  Width ="136px" ></ asp:Label >
        
</ form >
    
</ body >
</ HTML >
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值