android 获取本机的IP地址和mac物理地址的实现方法
程序员文章站
2024-03-06 22:38:38
获取本机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中线程的等待与唤醒