當前位置:編程學習大全網 - 網站源碼 - 安卓手機如何偽裝ip或者mac地址

安卓手機如何偽裝ip或者mac地址

android 是Linux內核,linux中mac地址是保存在/etc/init.d/networ 文件中的

但是在android中mac地址是直接寫在硬件中的,需要通過API 才能獲取

1、Android 獲取本機Mac 地址方法:

需要在AndroidManifest.xml文件中添加權限:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

public String getLocalMacAddress() {

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

WifiInfo info = wifi.getConnectionInfo();

return info.getMacAddress();

}

2、Android 獲取本機IP地址方法:

public 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()) {

return inetAddress.getHostAddress().toString();

}

}

}

} catch (SocketException ex) {

Log.e("WifiPreference IpAddress", ex.toString());

}

return null;

}

  • 上一篇:鯨虹傳媒彩虹自媒體是真的假的
  • 下一篇:天天酷跑中的坐騎機甲雲豹搭配什麽角色、寵物、精靈、寶物得分最高?
  • copyright 2024編程學習大全網