안드로이드 개발 질문/답변
(글 수 45,052)
AP에 연결되었을 때, 연결된 AP의 주소가 필요 합니다.
그런데 구글링하였을때, AP 주소 가져오는 코드나, 휴대폰의 IP 주소 가져오는 코드나 같던데
AP에 연결되면 휴대폰 IP는 AP의 IP로 사용되서 쓰는건가요?;
public static String getLocalIpAddressString()
{
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();
if (!inetAddress.isLoopbackAddress())
{
return inetAddress.getHostAddress().toString();
}
}
}
} catch (Exception ex) {
Log.e("IPADDRESS", ex.toString());
}
return null;
}




내부적으로 ap의 ip를 알 수는 없습니다.
외부와 통신을 해서 외부에서 ip를 알아내서 다시 결과를 내려줘야 합니다.
어쨋든 네트워크 통신을 1번은 해야 합니다.