Don't get IP of host
<p>I am writing to try to get the address IP of the host application via url.But when you run the application, even if I enter any url will also get the message <code>java.net.UnknownHostException</code>: Unable to resolve host. can yo help me!</p>

<p><strong>Source code</strong></p>

<pre><code>public class GetIp extends Activity implements OnClickListener {

private TextView txtUrl;
private ListView listInfo;
private Button btnGetIp;
String host;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_get_ip);
    txtUrl=(TextView)findViewById(R.id.txtUrl);
    listInfo=(ListView)findViewById(R.id.listInfo);
    btnGetIp=(Button)findViewById(R.id.btnGetIp);
    btnGetIp.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
        case R.id.btnGetIp:
            host = txtUrl.getText().toString();
            new LoadInfo().execute();
            break;

        default:
            break;
    }

}

public class LoadInfo extends AsyncTask&lt;Void, Void, Void&gt;
{
    private Boolean error = false;
    private String error_info = "";
    private InetAddress[] inetAddress = null;
    private List&lt;String&gt; hostList = new ArrayList&lt;String&gt;();
    private ProgressDialog pDialog;


    @Override
    protected void onPostExecute(final Void unused) {
        // TODO Auto-generated method stub
        pDialog.dismiss();
        if(error=true)
        {
            AlertDialog("Error: \n" + error_info);
        }
        else
        {
            AlertDialog("Load information complete!!!");
            ArrayAdapter&lt;String&gt; adapter
            = new ArrayAdapter&lt;String&gt;(
              GetIp.this,
              android.R.layout.simple_list_item_1,
              hostList);

            listInfo.setAdapter(adapter);
        }
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        pDialog = new ProgressDialog(GetIp.this);
        pDialog.setMessage("Loading data...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        doGet();
        return null;
    }

    private void doGet(){

        try {
            URL url = new URL(host);
            URLConnection connection = url.openConnection();
            connection.addRequestProperty("Protocol", "Http/1.1");
            connection.addRequestProperty("Connection", "keep-alive");
            connection.addRequestProperty("Keep-Alive", "1000");
            connection.addRequestProperty("User-Agent", "Web-Agent");
            Scanner s = new Scanner(connection.getInputStream());
      inetAddress = InetAddress.getAllByName(s.nextLine());

      for(int i = 0; i &lt; inetAddress.length; i++){

       hostList.add(inetAddress[i].getClass() + " -\n"
         + inetAddress[i].getHostName() + "\n"
         + inetAddress[i].getHostAddress());
         }

     } catch (UnknownHostException e) {

      e.printStackTrace();

      error = true;
      error_info = e.toString();
     }catch (Exception e) {
        // TODO: handle exception
         e.printStackTrace();
    }

       }

    public void AlertDialog (final String mess)
    {
        GetIp.this.runOnUiThread(new Runnable() {
            public void run() {
                AlertDialog.Builder builder = new AlertDialog.Builder(
                        GetIp.this);
                builder.setTitle("Thông báo!");
                builder.setMessage(mess)
                        .setCancelable(false)
                        .setPositiveButton("Đồng ý",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int id) {
                                    }
                                });
                AlertDialog alert = builder.create();
                alert.show();
            }
        });
}

}   
}
</code></pre>
