Android gets the physical address of the IP and native

Source: Internet
Author: User
Tags get ip

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.