Whois简易查询Android版
2011年11月29日
1 条评论
有空玩了下android,配置环境比较啰嗦。google下
贴效果图;

效果简单 之前是模仿了cnblog的一篇文章。不过他是抓url。我是用socket。
后缀还没细分,喜欢的人自己研究去,贴代码
public class MyWhois extends Activity { private TextView vResult; private EditText eKeyWord; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button sButton1 = (Button)findViewById(R.id.Submit); vResult = (TextView)findViewById(R.id.ResultView); eKeyWord = (EditText)findViewById(R.id.KeyWord); //注册点击事件监听者 sButton1.setOnClickListener(new OnClickListener() { public void onClick(View aView) { TextView vResult = (TextView)findViewById(R.id.ResultView); vResult.setText("正在查询中,请稍等!"); //新建查询线程,否则UI界面会假死 Thread mThread = new Thread(new Runnable() { public void run() { String whoisMes=""; try { try { String domain=eKeyWord.getText().toString(); String IP="whois.cnnic.cn"; if(domain.contains(".com")||domain.contains(".com")){ IP="whois.internic.net"; } Socket socket = new Socket(IP, 43); InputStream Is = socket.getInputStream(); OutputStream Os = socket.getOutputStream(); DataInputStream DIS = new DataInputStream(Is); PrintStream PS = new PrintStream(Os); DataInputStream in = new DataInputStream(System.in); PS.println(domain); System.out.println("please wait whois's message..."); boolean TF = false; while (DIS.read() > 0) { String tempStr = DIS.readLine(); whoisMes = whoisMes + tempStr + "\r\n"; } whoisMes=new String(whoisMes.getBytes("ISO-8859-1"),"utf-8"); System.out.println(whoisMes); DIS.close(); PS.close(); Is.close(); Os.close(); socket.close(); } catch (Exception e) { System.out.println("Error:" + e); } //返回的数据需要使用'\n'来换行! Message mg = Message.obtain(); mg.obj = whoisMes; mHandler.sendMessage(mg); } catch (Exception e) { e.printStackTrace(); } } }); mThread.start(); } } ); } //定义一个Handler private Handler mHandler = new Handler(){ public void handleMessage(Message msg){ String m = (String) msg.obj; if(m.length()<=0) { vResult.setText("查询结果为空."); } else { vResult.setText(m); } } }; }