.:: Jasa Membuat Aplikasi Website,Desktop,Android Order Now..!! | | Order Now..!! Jasa Membuat Project Arduino,Robotic,Print 3D ::.

Gets IP addresses of a given host - InetAddress.getAllByName()

0 komentar


بِسْــــــــــــــــمِ اﷲِالرَّحْمَنِ اارَّحِيم
bismillaahirrahmaanirrahiim

السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
Assalamu'alaikum warahmatullahi wabarakatuh

java.net.InetAddress is a class of Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in practice you'll have an instance of either Inet4Address or Inet6Address (this class cannot be instantiated directly). Most code does not need to distinguish between the two families, and should use InetAddress.

The method getAllByName() gets all IP addresses associated with the given host identified by name or literal IP address. The IP address is resolved by the configured name service. If the host name is empty or null an UnknownHostException is thrown. If the host name is a literal IP address string an array with the corresponding single InetAddress is returned.

This example list all IP addresses associated with the user enter host name.

Note:

"android.permission.INTERNET" is needed.

For Applications targeting the Honeycomb SDK or higher, cannot attempts to perform a networking operation on its main thread. Otherwise, NetworkOnMainThreadException will be thrown. So the network operation is moved into AsyncTask.

I haven't IPv6 connection currently, I don't know if it will show Inet6Address with IPv6 connection. If you have, please let me know.

Java Code:

  
package com.AndroidInet;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

public class AndroidInetActivity extends Activity {

EditText hostinput;
TextView info;
Button btnTest;
ListView resultList;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
hostinput = (EditText)findViewById(R.id.testhost);
info = (TextView)findViewById(R.id.info);
resultList = (ListView)findViewById(R.id.result);
btnTest = (Button)findViewById(R.id.test);
btnTest.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View view) {
info.setText("Wait...");
new Task().execute();

}});
}



private class Task extends AsyncTask{
Boolean error = false;
String error_info = "";
InetAddress[] inetAddress = null;

List hostList = new ArrayList();

@Override
protected Void doInBackground(Void... arg0) {
doTest();
return null;
}

@Override
protected void onPostExecute(Void result) {
if(error){
info.setText("Error: \n" + error_info);
}else{
info.setText("Finished");

ArrayAdapter adapter
= new ArrayAdapter(
AndroidInetActivity.this,
android.R.layout.simple_list_item_1,
hostList);

resultList.setAdapter(adapter);
}

super.onPostExecute(result);
}

private void doTest(){

String host = hostinput.getText().toString();

try {
inetAddress = InetAddress.getAllByName(host);

for(int i = 0; i < 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();
}

}
}
}

XML Code:

 







Cheers Guys!!!!!

Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
NB :: Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code, membeli hardware elektronika untuk kepentingan Perusahaan maupun Tugas Akhir (TA/SKRIPSI), Insyaallah Saya siap membantu, untuk Respon Cepat dapat menghubungi kami, melalui :

No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com


atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :

ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِين
Alhamdulilah hirobil alamin

وَ السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
wassalamualaikum warahmatullahi wabarakatuh


Artikel Gets IP addresses of a given host - InetAddress.getAllByName() , Diterbitkan oleh scodeaplikasi pada Minggu, 24 Februari 2013. Semoga artikel ini dapat menambah wawasan Anda. Website ini dipost dari beberapa sumber, bisa cek disini sumber, Sobat diperbolehkan mengcopy paste / menyebar luaskan artikel ini, karena segala yang dipost di public adalah milik public. Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code ,Dengan Cara menghubungi saya Ke Email: Fajarudinsidik@gmail.com, atau No Hp/WA : (fajar) : 085369237896, (puat) : 085267792168.

Tawk.to