如何检查Android中可用/已连接的服务器或IP地址

时间:2012-04-04 11:05:44

标签: java android networking connection android-networking

如何知道在android中可用/连接的服务器/ IP地址。 我试试这段代码

final EditText ed_ip = (EditText)findViewById(R.id.ed_server);
Button btn_ip_save = (Button)findViewById(R.id.btn_save_ip);

btn_ip_save.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

String str_serverip = ed_ip.getText().toString();
int timeout = 2000;

byte [] b = str_serverip.getBytes();

boolean addr = InetAddress.getByAddress(b).isReachable(timeout);

if(addr == true)
{
       txt.setText("Response");
      Toast.makeText(IpConfig.this, "Reachable", Toast.LENGTH_LONG).show();

}else {

    txt.setText("Not Response");
    Toast.makeText(IpConfig.this, "Not", Toast.LENGTH_LONG).show();
    }


}       
除了127.0.0.1

之外,它总是拒绝连接

如何检查plz指导我..

0 个答案:

没有答案