域名注册在java中为Android [英] whois in java for Android

查看:163
本文介绍了域名注册在java中为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做的whois在Java中为Android培训关于流和TCP连接。

I'm making a whois in java for android to train about streams and tcp connections.

不过,我有一个问题。我有一个PHP脚本,我写了前一段时间我正尝试使Java中的相同。

But I have a problem. I have a php script, I wrote some time ago and I´m trying to make the same in java.

这是我的Java code:

this is my java code :

 public String consultawhois(String domain,String tld)
    {
        String domquest = domain + "." + tld;
        String resultado = "";
        Socket theSocket;
        String hostname = "whois.internic.net";
        int port = 43;
        try {
          theSocket = new Socket(hostname, port, true);
          Writer out = new OutputStreamWriter(theSocket.getOutputStream());
          out.write(domquest + "\r\n");
          out.flush();
          DataInputStream theWhoisStream;
          theWhoisStream = new DataInputStream(theSocket.getInputStream());
          String s;
          while ((s = theWhoisStream.readLine()) != null) {
            resultado = resultado + s + "\n";
          }
        }
        catch (IOException e) {
        }

        return resultado;
    }

服务器的答案是不正确的,我认为问题是,我要送一个坏的查询。我送的查询是dominio.com \\ r \\ n,并在我的PHP的whois code,它完美的作品。

The answer of the server is not correct and I think the problem is that I'm sending a bad query. The query I send is "dominio.com\r\n" and in my php whois code, it works perfectly.

推荐答案

看来,DNS查询多个记录相匹配。至少,这是我怎么际preT的响应。在返回的效应初探应该可以看到以下行:

It seems that the DNS query matches multiple records. At least, that is how I interpret the response. In the returned reponse you should see the following line:

要挑出一个记录,以XXX,其中xxx是一个看它
  上面显示的记录。如果记录是相同的,找一找
  用= XXX来接收全屏显示为每个记录。

To single out one record, look it up with "xxx", where xxx is one of the of the records displayed above. If the records are the same, look them up with "=xxx" to receive a full display for each record.

所以,如果你prePEND与查询=只返回该记录的数据。下面为我​​工作。

So if you prepend the query with "=" it returns the data of that record only. The following worked for me.

public String consultawhois(String domain,String tld)
{
    String domquest = domain + "." + tld;
    String resultado = "";
    Socket theSocket;
    String hostname = "whois.internic.net";
    int port = 43;
    try {
      theSocket = new Socket(hostname, port, true);
      Writer out = new OutputStreamWriter(theSocket.getOutputStream());
      out.write("="+domquest + "\r\n");
      out.flush();
      DataInputStream theWhoisStream;
      theWhoisStream = new DataInputStream(theSocket.getInputStream());
      String s;
      while ((s = theWhoisStream.readLine()) != null) {
        resultado = resultado + s + "\n";
      }
    }
    catch (IOException e) {
    }

    return resultado;
}

有一点要考虑:使用英语的方法名,变量等,而不是西班牙语。它会让你的code更容易阅读国际。编程语言本身也使用英语单词。尽量避免英语的一个奇怪的组合和你的母语。

One thing to consider: Use English for method names, variables, etc. instead of Spanish. It will make your code easier to read internationally. The programming language itself also uses English words. Try to avoid a strange mix of English and your native language.

这篇关于域名注册在java中为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆