android 获取本机的IP地址和mac物理地址的实现方法
程序员文章站
2024-03-05 23:31:07
获取本机ip地址
public string getlocalipaddress() {
wifimanager wifimanager = (w...
获取本机ip地址
public string getlocalipaddress() { wifimanager wifimanager = (wifimanager) getsystemservice(android.content.context.wifi_service); wifiinfo wifiinfo = wifimanager.getconnectioninfo(); int ipaddress = wifiinfo.getipaddress(); try { return inetaddress.getbyname(string.format("%d.%d.%d.%d", (ipaddress & 0xff), (ipaddress >> 8 & 0xff), (ipaddress >> 16 & 0xff), (ipaddress >> 24 & 0xff))).tostring(); } catch (unknownhostexception e) { // todo auto-generated catch block e.printstacktrace(); } return null; }
获取本机的物理地址
public string getlocalmacaddress() { wifimanager wifi = (wifimanager) getsystemservice(context.wifi_service); wifiinfo info = wifi.getconnectioninfo(); return info.getmacaddress(); }
以上就是android 获取手机 ip和mac地址的方法,希望能帮助到读者,谢谢大家对本站的支持!
上一篇: java实现输入输出流代码分享
下一篇: Android拍照上传功能示例代码