C# SEO:为.SE域工作的whois服务器?
我正在开发一个小型域检查器,但无法使.SE正常工作:C# SEO:为.SE域工作的whois服务器?,c#,whois,C#,Whois,我正在开发一个小型域检查器,但无法使.SE正常工作: public string Lookup(string domain, RecordType recordType, SeoToolsSettings.Tld tld) { TcpClient tcp = new TcpClient(); tcp.Connect(tld.WhoIsServer, 43); string strDomain = recordType.ToString() + " " + domain +
public string Lookup(string domain, RecordType recordType, SeoToolsSettings.Tld tld)
{
TcpClient tcp = new TcpClient();
tcp.Connect(tld.WhoIsServer, 43);
string strDomain = recordType.ToString() + " " + domain + "\r\n";
byte[] bytDomain = Encoding.ASCII.GetBytes(strDomain.ToCharArray());
Stream s = tcp.GetStream();
s.Write(bytDomain, 0, strDomain.Length);
StreamReader sr = new StreamReader(tcp.GetStream(), Encoding.ASCII);
string strLine = "";
StringBuilder builder = new StringBuilder();
while (null != (strLine = sr.ReadLine()))
{
builder.AppendLine(strLine);
}
tcp.Close();
if (tld.WhoIsDelayMs > 0) System.Threading.Thread.Sleep(tld.WhoIsDelayMs);
return builder.ToString();
}
我已经尝试了whois服务器whois.nic-se.se和whois.iis.se,我一直得到:
# Copyright (c) 1997- .SE (The Internet Infrastructure Foundation).
# All rights reserved.
# The information obtained through searches, or otherwise, is protected
# by the Swedish Copyright Act (1960:729) and international conventions.
# It is also subject to database protection according to the Swedish
# Copyright Act.
# Any use of this material to target advertising or
# similar activities is forbidden and will be prosecuted.
# If any of the information below is transferred to a third
# party, it must be done in its entirety. This server must
# not be used as a backend for a search engine.
# Result of search for registered domain names under
# the .SE top level domain.
# The data is in the UTF-8 character set and the result is
# printed with eight bits.
"domain google.se" not found.
编辑:
我试着换成UTF8,但没有其他结果
当我尝试从系统内部使用whois时,我得到了正确的结果,但我的代码没有,甚至没有使用SE.whois-servers.net
/NielsHmmm,在我的Mac上做
whois google.se
时,我得到以下信息:
# Copyright (c) 1997- .SE (The Internet Infrastructure Foundation).
# All rights reserved.
# The information obtained through searches, or otherwise, is protected
# by the Swedish Copyright Act (1960:729) and international conventions.
# It is also subject to database protection according to the Swedish
# Copyright Act.
# Any use of this material to target advertising or
# similar activities is forbidden and will be prosecuted.
# If any of the information below is transferred to a third
# party, it must be done in its entirety. This server must
# not be used as a backend for a search engine.
# Result of search for registered domain names under
# the .SE top level domain.
# The data is in the UTF-8 character set and the result is
# printed with eight bits.
state: active
domain: google.se
holder: googoo5855-00001
admin-c: -
tech-c: -
billing-c: -
created: 2008-10-20
modified: 2010-09-18
expires: 2011-10-20
transferred: 2009-03-06
nserver: ns1.google.com
nserver: ns2.google.com
nserver: ns3.google.com
nserver: ns4.google.com
dnssec: unsigned delegation
status: ok
registrar: MarkMonitor Inc
所以这可能只是你的代码。也许您必须使用非ASCII编码来执行请求,例如UTF8?我终于解决了这个问题
使用wireshark,我看到来自sysinternals的whois没有添加“域”部分:
字符串strDomain=recordType.ToString()+“”+域+“\r\n”
(recordType.ToString==“域”)
所以当我移除它时,它就起作用了 不查看您的代码为什么不: 示例@ 对于
par.se
IP Found:
- 193.13.249.142
Host name:
- parweb1.par.se
Aliases:
none
IP address list:
- 193.13.249.142
如果您只需要IP的成熟信息,也可以使用我的页面进行测试
{ip测试}
按钮事件
protected void btnCheck_Click(object sender, EventArgs e)
{
DomainCheck domain = new DomainCheck();
string ip = domain.GetIPFromDomain(txtDomain.Text.Trim());
litResponse.Text = String.Format(
"IP{0} Found:<br/> - <strong>{1}</strong><br/>{2}",
ip.Contains(",") ? "'s" : "",
ip.Replace(",", "<br/> - "), domain.VerifyIP(ip));
}
protectedvoidbtncheck\u单击(对象发送方,事件参数e)
{
DomainCheck domain=新建DomainCheck();
字符串ip=domain.GetIPFromDomain(txtDomain.Text.Trim());
litResponse.Text=String.Format(
“找到IP{0}:
-{1}
{2}”,
ip.包含(“,”)“:”,
ip.Replace(“,”,“
-”,domain.VerifyIP(ip));
}
域检查代码:
public class DomainCheck
{
public DomainCheck() { }
public string VerifyIP(string ipAddress)
{
if (String.IsNullOrEmpty(ipAddress))
return "IP Address is invalid!";
string r = "";
if (ipAddress.Contains(","))
{
foreach (string ip in ipAddress.Split(','))
r += String.Format("<br/><br/>#### <em>Checking {0}</em>{1}", ip, CheckIPAddress(ip));
}
else
r += CheckIPAddress(ipAddress);
return r;
}
public string GetIPFromDomain(string hostname)
{
string r = "";
IPAddress[] addresslist = Dns.GetHostAddresses(hostname);
foreach (IPAddress theaddress in addresslist)
{
r += String.Format("{0},", theaddress.ToString());
}
return String.IsNullOrEmpty(r) ? null : r.TrimEnd(',');
}
private string CheckIPAddress(string ipAddress)
{
string r = "";
try
{
IPAddress hostIPAddress = IPAddress.Parse(ipAddress);
IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress);
// Get the IP address list that resolves to the host names contained in
// the Alias property.
IPAddress[] address = hostInfo.AddressList;
// Get the alias names of the addresses in the IP address list.
String[] alias = hostInfo.Aliases;
r += String.Format(
"<br/>Host name: <br/>- <strong>{0}</strong><br/>Aliases: ",
hostInfo.HostName);
if (alias.Length == 0)
r += "<br/><em>none</em>";
else
for (int index = 0; index < alias.Length; index++)
r += String.Format("<br/>- <strong>{0}</strong>", alias[index]);
r += "<br/>IP address list: ";
if (address.Length == 0)
r += "<br/><em>none</em>";
else
for (int index = 0; index < address.Length; index++)
r += String.Format("<br/>- <strong>{0}</strong>", address[index]);
}
catch (SocketException e)
{
r = String.Format(
"SocketException caught!!!<br/>Source : {0}<br/>Message : {1}",
e.Source, e.Message);
}
catch (FormatException e)
{
r = String.Format(
"FormatException caught!!!<br/>Source : {0}<br/>Message : {1}",
e.Source, e.Message);
}
catch (ArgumentNullException e)
{
r = String.Format(
"ArgumentNullException caught!!!<br/>Source : {0}<br/>Message : {1}",
e.Source, e.Message);
}
catch (Exception e)
{
r = String.Format(
"Exception caught!!!<br/>Source : {0}<br/>Message : {1}",
e.Source, e.Message);
}
return r;
}
}
公共类域检查
{
公共域检查(){}
公共字符串验证IP(字符串IP地址)
{
if(String.IsNullOrEmpty(ipAddress))
返回“IP地址无效!”;
字符串r=“”;
if(ipAddress.Contains(“,”))
{
foreach(ipAddress.Split(',')中的字符串ip)
r+=String.Format(“
#####检查{0}{1}”,ip,检查地址(ip));
}
其他的
r+=检查IP地址(IP地址);
返回r;
}
公共字符串GetIPFromDomain(字符串主机名)
{
字符串r=“”;
IPAddress[]addresslist=Dns.GetHostAddresses(主机名);
foreach(IP地址地址地址列表中的地址)
{
r+=String.Format(“{0},”,theaddress.ToString());
}
返回字符串.IsNullOrEmpty(r)?null:r.TrimEnd(',');
}
专用字符串检查IP地址(字符串IP地址)
{
字符串r=“”;
尝试
{
IPAddress hostIPAddress=IPAddress.Parse(IPAddress);
IPHostEntry hostInfo=Dns.GetHostByAddress(hostIPAddress);
//获取解析为中包含的主机名的IP地址列表
//别名属性。
IPAddress[]地址=主机信息。地址列表;
//获取IP地址列表中地址的别名。
String[]alias=hostInfo.alias;
r+=String.Format(
“
主机名:
-{0}
别名:”,
hostInfo.HostName);
如果(alias.Length==0)
r+=“
无”;
其他的
for(int index=0;index -{0}”,别名[index]);
r+=“
IP地址列表:”;
if(address.Length==0)
r+=“
无”;
其他的
for(int index=0;index -{0}”,地址[索引];
}
捕获(SocketException e)
{
r=String.Format(
“已捕获SocketException!!!
源:{0}
消息:{1}”,
e、 来源(e.Message);
}
捕获(格式化异常)
{
r=String.Format(
“捕获到FormatException!!!
源:{0}
消息:{1}”,
e、 来源(e.Message);
}
捕获(e)
{
r=String.Format(
“ArgumentNullException已捕获!!!
源:{0}
消息:{1}”,
e、 来源(e.Message);
}
捕获(例外e)
{
r=String.Format(
“捕获异常!!!
源:{0}
消息:{1}”,
e、 来源(e.Message);
}
返回r;
}
}
您的代码是否适用于其他TLD的whois服务器?我在Win7上使用Sysinternalswhois google.se
获得了正确的输出是的,我的代码适用于其他TLD。我将whois.internic.net用于.com域,这很好用。嗯。。。将尝试使用其他编码。。。但是有没有可能确定你在mac上使用的服务器是谁?请注意,我已经让它在whois服务器whois.internic.net的.com域中工作。