如何使用Java代码获取Android移动终端Mac地址

如何使用Java代码获取Android移动终端Mac地址,第1张

这个是在android上获取MAC的方法

WifiManager wifi = (WifiManager) getSystemService(ContextWIFI_SERVICE);

WifiInfo info = wifigetConnectionInfo();

String mac = infogetMacAddress();

package comalphatest;

import javaioBufferedReader;

import javaioIOException;

import javaioInputStream;

import javaioInputStreamReader;

import javaioLineNumberReader;

public class GetMac {

/

java获取客户端网卡的MAC地址

@param args

/

public static void main(String[] args) {

GetMac get = new GetMac();

Systemoutprintln("1="+getgetMAC());

Systemoutprintln("2="+getgetMAC("127001"));

}

// 1获取客户端ip地址( 这个必须从客户端传到后台):

// jsp页面下,很简单,requestgetRemoteAddr() ;

// 因为系统的VIew层是用JSF来实现的,因此页面上没法直接获得类似request,在bean里做了个强制转换

// public String getMyIP() {

// try {

// FacesContext fc = FacesContextgetCurrentInstance();

// >

我没看你的代码,给你一个可运行的代码,你自己看看好吗:

//这个例子使用了J2SE50的ProcessBuilder类执行外部的程序,相对于 Runtimeexec ,

//它更方便,可以设置环境变量等。这里使用它在windows下读取物理网卡的地址。

import javaio;

import javautil;

public class ProcessBuilderShow{

public static List<String> getPhysicalAddress(){

Process p = null;

//物理网卡列表

List<String> address = new ArrayList<String>();

try{

//执行ipconfig /all命令

p = new ProcessBuilder("ipconfig", "/all")start();

}catch (IOException e){

return address;

}

byte[] b = new byte[1024];

StringBuffer sb = new StringBuffer();

//读取进程输出值

InputStream in = pgetInputStream();

try{

while (inread(b)>0){

sbappend(new String(b));

}

}catch (IOException e1){

}finally{

try{

inclose();

}catch (IOException e2){

}

}

//以下分析输出值,得到物理网卡

String rtValue = sbsubstring(0);

int i = rtValueindexOf("Physical Address :");

while(i>0){

rtValue = rtValuesubstring(i + "Physical Address :"length());

addressadd(rtValuesubstring(0,18));

i = rtValueindexOf("Physical Address :");

}

return address;

}

public static void main(String[] args){

List<String> address = ProcessBuilderShowgetPhysicalAddress();

for(String add:address){

Systemoutprintf("物理网卡地址:%s%n", add);

}

}

}

以上就是关于如何使用Java代码获取Android移动终端Mac地址全部的内容,包括:如何使用Java代码获取Android移动终端Mac地址、Java web 怎么得到客户端的Mac地址、一个获取MAC地址的JAVA程序,不知道错误再哪谢谢!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10209080.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-06
下一篇 2023-05-06

发表评论

登录后才能评论

评论列表(0条)

保存