android 獲取裝置IP和Mac地址
獲取Mac地址:
- public String getLocalMacAddress() {
- String Mac=null;
- try{
- String path="sys/class/net/wlan0/address";
- if((new File(path)).exists())
- {
- FileInputStream fis = new FileInputStream(path);
- byte[] buffer = new byte[8192];
- int byteCount = fis.read(buffer);
- if(byteCount>0)
- {
- Mac = new String(buffer, 0, byteCount, "utf-8");
- }
- }
- Log.v("daming.zou***wifi**mac11**", ""+Mac);
- if(Mac==null||Mac.length()==0)
- {
- path="sys/class/net/eth0/address";
- FileInputStream fis_name = new FileInputStream(path);
- byte[] buffer_name = new byte[8192];
- int byteCount_name = fis_name.read(buffer_name);
- if(byteCount_name>0)
- {
- Mac = new String(buffer_name, 0, byteCount_name, "utf-8");
- }
- }
- Log.v("daming.zou***eth0**mac11**", ""+Mac);
- // String path="sys/class/net/eth0/address";
- // FileInputStream fis_name = new FileInputStream(path);
- // byte[] buffer_name = new byte[8192];
- // int byteCount_name = fis_name.read(buffer_name);
- // if(byteCount_name>0)
- // {
- // mac = new String(buffer_name, 0, byteCount_name, "utf-8");
- // }
- // if(mac.length()==0||mac==null){
- // path="sys/class/net/eth0/wlan0";
- // FileInputStream fis = new FileInputStream(path);
- // byte[] buffer = new byte[8192];
- // int byteCount = fis.read(buffer);
- // if(byteCount>0)
- // {
- // mac = new String(buffer, 0, byteCount, "utf-8");
- // }
- // }
- if(Mac.length()==0||Mac==null){
- return "";
- }
- }catch(Exception io){
- Log.v("daming.zou**exception*", ""+io.toString());
- }
- Log.v("xulongheng*Mac", Mac);
- return Mac.trim();
- // WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
- // WifiInfo info = wifi.getConnectionInfo();
- // if (info.getMacAddress() != null) {
- // return info.getMacAddress().toString();
- // }
- }
獲取Ip:
- public String GetHostIp() {
- 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()
- && InetAddressUtils.isIPv4Address(inetAddress
- .getHostAddress())) {
- if (!inetAddress.getHostAddress().toString()
- .equals("null")
- && inetAddress.getHostAddress() != null) {
- return inetAddress.getHostAddress().toString().trim();
- }
- }
- }
- }
- } catch (SocketException ex) {
- Log.e("WifiPreference IpAddress", ex.toString());
- }
- return "";
- }
相關文章
- java獲取ip地址和mac地址JavaMac
- Java 中獲取MAC地址 和IP地址JavaMac
- ASPNET獲取IP地址 MAC地址Mac
- reactnative獲取裝置真實ip地址和ip對映的地理位置React
- 最簡單的C# 獲取 MAC 地址 IP 地址C#Mac
- Android下如何獲取Mac地址?AndroidMac
- saltstack獲取IP地址
- 獲取IP地址方法
- 獲取IP地址命令
- Java獲取本機名稱、本機MAC地址、IP地址JavaMac
- 美國ip地址如何獲取?
- 獲取真實IP地址
- Python 基礎練習 —— 獲取本機 Mac 地址、ip 地址和主機名PythonMac
- Oracle中獲取主機名和IP地址Oracle
- ASP.NET獲取客戶端IP及MAC地址ASP.NET客戶端Mac
- 獲取本地IP和mac等資訊Mac
- 區域網內獲取周圍裝置的ip和埠
- 如何獲取海外住宅IP地址?
- jQuery獲取本機ip地址jQuery
- Java獲取本機ip地址Java
- Android獲取硬體裝置資訊Android
- 在cmd中獲取ip地址和主機名
- JSF/JAVA 根據IP獲取客戶端Mac地址JSJava客戶端Mac
- python獲取本機IP、mac地址、計算機名PythonMac計算機
- java獲取客戶端ip和macJava客戶端Mac
- java獲取本機的ip地址Java
- Apapche獲取真實IP地址方法
- 獲取本地的IP地址(內網)內網
- DHCP獲取IP地址的過程
- Oracle獲取連線的IP地址Oracle
- iOS 獲取裝置uuid,公網ip,手機ip等資訊iOSUI
- IP地址和MAC地址的關係Mac
- iOS 獲取手機外網和內網IP地址iOS內網
- Android手機怎麼獲取印表機的IP地址呢Android
- 獲取客戶端Mac地址客戶端Mac
- php怎麼獲取mac地址?PHPMac
- 獲取IP地址的途徑有哪些?要如何保護IP地址不被竊取?
- PHP獲取IP地址的方法,防止偽造IP地址注入攻擊PHP