Android obtains Internet and Intranet IP addresses.
Very late. Live code:
/*** Get the Internet IP address (to access the Url, put it in the background thread for processing) ** @ Title: GetNetIp * @ Description: * @ param @ return * @ return String * @ throws */public static String GetNetIp () {URL infoUrl = null; InputStream inStream = null; String ipLine = ""
1. How to obtain the MAC address of a local machine from Android:
You need to add permissions to the androidmanifest. xml file:
Public String getlocalmacaddress () {wifimanager WiFi = (wifimanager) getsystemservice (context. wifi_service); wifiinfo info = wifi. getconnectioninfo (); Return info. getmacaddress ();}
2. How to obtain the local IP address for
Try { //get all the network devices on your phone (WiFi module)enumerationnetworkinterface.getnetworkinterfaces (); //Enumerate all network devices while(Netinterface.hasmoreelements ()) {NetworkInterface ni=netinterface.nextelement (); //gets the IP address that is bound to the current network deviceenumerationni.getinetaddresses (); while(Ips.hasmoreelements ()) {//Print the bound IPSystem.out.println (Ips.nextelement (). get
1. How to obtain the MAC address of a local machine from Android:
You need to add permissions to the androidmanifest. xml file:
public String getLocalMacAddress() { WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); return info.getMacAddress(); }
2. How to obtain the local IP address for
1 Get IPV4 Addresspublicstringgetlocalipaddress () { Stringaddress= "0";try{ Enumeration 2 Get IPV6 address publicstringgetlocalipaddress () { Stringaddress= "0";try{ EnumerationThis article is from the "Jackyanngo" blog, make sure to keep this source http://jackyanngo.blog.51cto.com/5263823/1614612[Android] Get IP address
1 Get IPV4 Addresspublicstringgetlocalipaddress () { Stringaddress= "0";try{ Enumeration 2 Get IPV6 address publicstringgetlocalipaddress () { Stringaddress= "0";try{ EnumerationThis article is from the "Jackyanngo" blog, make sure to keep this source http://jackyanngo.blog.51cto.com/5263823/1614611[Android] Get IP address
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.