// wifi 가 연결 됬는지 확인 하는것
ConnectivityManager manager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean wificon = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
if(wificon == false){
return; // 연결이 됬는지 확인
}
// wifi 정보 가져오기
WifiManager wifimanager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
DhcpInfo dhcpInfo = wifimanager.getDhcpInfo();
int wIp = dhcpInfo.ipAddress;
int wNetmask = dhcpInfo.netmask;
int wGateway = dhcpInfo.gateway;
int wDns1 = dhcpInfo.dns1;
String ip = String.format("%d.%d.%d.%d", (wIp & 0xff), (wIp >> 8 & 0xff), (wIp >> 16 & 0xff), (wIp >> 24 & 0xff));
String subnet = String.format("%d.%d.%d.%d", (wNetmask & 0xff), (wNetmask >> 8 & 0xff), (wNetmask >> 16 & 0xff), (wNetmask >> 24 & 0xff));
String gateway = String.format("%d.%d.%d.%d", (wGateway & 0xff), (wGateway >> 8 & 0xff), (wGateway >> 16 & 0xff), (wGateway >> 24 & 0xff));
String dns = String.format("%d.%d.%d.%d", (wDns1 & 0xff), (wDns1 >> 8 & 0xff), (wDns1 >> 16 & 0xff), (wDns1 >> 24 & 0xff));
댓글 없음:
댓글 쓰기