Tag: Gets the physical address of the ip native
<span style= "FONT-SIZE:18PX;" >/** * Get IP * * @return */public static String getlocalipaddress () {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 () && inetaddress instanceof inet4address) {//Return inetaddress.getaddress (). toString (); return inetaddress.gethostaddress (). ToString ();}}} catch (SocketException ex) {LOG.E ("basescantvdeviceclient", "get native IP false =" + ex.tostring ());} return null;} public static String Getlocalipaddress (context context) {Wifimanager Wifimanager = (Wifimanager) Context.getsystemservice (Context.wifi_service); Wifiinfo wifiinfo = Wifimanager.getconnectioninfo (); String ipAddress = Formatip (Wifiinfo.getipaddress ()); return ipAddress;} public static String forMatIP (int IP) {return formatter.formatipaddress (IP);} /Get native IP address public static String getlocalipaddress (Context ctx) {Wifimanager Wifimanager = (Wifimanager) Ctx.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 >> & 0xff) (ipAddress >> 0xff)). ToString (); catch (Unknownhostexception e) {return null;}} Gets the physical address of the local public static String getlocalmacaddress (Context ctx) {Wifimanager WiFi = (wifimanager) ctx.getsystemservice ( Context.wifi_service); Wifiinfo info = wifi.getconnectioninfo (); return info.getmacaddress ();} </span>
Android gets the physical address of the IP and native