WIFI veya 3G bağlantısını kullanarak bir aygıtın IP adresini almaya çalışıyorum. IP adresi IPV6 biçiminde anlaşılamıyor. IPv4 formatında IP adresi istiyorum.Google'a yaptım ama dint uygun herhangi bir çözüm buldu. BuradaIP_ADDRESS IPV4 biçiminde nasıl edinilir
Bir cihazın IP adresini almak için kullanıyorum kodudur
public String getLocalIpAddress() {
try {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
{
InetAddress inetAddress = enumIpAddr.nextElement();
System.out.println("ip1--:" + inetAddress);
System.out.println("ip2--:" + inetAddress.getHostAddress());
if (!inetAddress.isLoopbackAddress()) {
String ip = inetAddress.getHostAddress().toString();
System.out.println("ip---::" + ip);
EditText tv = (EditText) findViewById(R.id.ipadd);
tv.setText(ip);
return inetAddress.getHostAddress().toString();
}
}
}
} catch (Exception ex) {
Log.e("IP Address", ex.toString());
}
return null;
}
bu çıktıya alıyorum:
ip1--:/fe80::5054:ff:fe12:3456%eth0%2
ip2--:fe80::5054:ff:fe12:3456%eth0
Böyle görüntülenmesi gereken:
192.168.1.1
lütfen bana yardım edin ..
Null sonucunu önlemek için izin vermeyin : –
Vyacheslav
"ipv4" olarak nerede ve nasıl bildirilir – CrazyMind