C#查询Whois代码

None.gif using  System;
None.gif
using  System.Data;
None.gif
using  System.Configuration;
None.gif
using  System.Web;
None.gif
using  System.Web.Security;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.WebControls.WebParts;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.Net;
None.gif
using  System.Net.Sockets;
None.gif
using  System.Text;
None.gif
public  partial  class  _Default : System.Web.UI.Page 
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif    
protected void Button1_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
string _r = Whois(TextBox1.Text.Trim());
InBlock.gif        
InBlock.gif        Response.Write(_r.Replace(
"\r\n","<br>"));
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 域名注册查询
InBlock.gif    
/// </summary>
InBlock.gif    
/// <param name="domain">输入域名,不包含www</param>
ExpandedSubBlockEnd.gif    
/// <returns></returns>

InBlock.gif    public static string Whois(string domain)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (domain == null)
InBlock.gif            
throw new ArgumentNullException();
InBlock.gif        
int ccStart = domain.LastIndexOf(".");
InBlock.gif        
if (ccStart < 0 || ccStart == domain.Length)
InBlock.gif            
throw new ArgumentException();
InBlock.gif        
string ret = "";
InBlock.gif        Socket s 
= null;
InBlock.gif        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string cc = domain.Substring(ccStart + 1);
InBlock.gif            s 
= new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
InBlock.gif            s.Connect(
new IPEndPoint(Dns.Resolve(cc + ".whois-servers.net").AddressList[0], 43));
InBlock.gif            s.Send(Encoding.ASCII.GetBytes(domain 
+ "\r\n"));
InBlock.gif            
byte[] buffer = new byte[1024];
InBlock.gif            
int recv = s.Receive(buffer);
InBlock.gif            
while (recv > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ret 
+= Encoding.ASCII.GetString(buffer, 0, recv);
InBlock.gif                recv 
= s.Receive(buffer);
ExpandedSubBlockEnd.gif            }

InBlock.gif            s.Shutdown(SocketShutdown.Both);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
throw new SocketException();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (s != null)
InBlock.gif                s.Close();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
return ret;
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/xufung/archive/2007/01/17/622762.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值