1. Java web 怎么得到客户端的Mac地址
package com.alpha.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
public class GetMac {
/**
* java获取客户端网卡的MAC地址
*
* @param args
*/
public static void main(String[] args) {
GetMac get = new GetMac();
System.out.println("1="+get.getMAC());
System.out.println("2="+get.getMAC("127.0.0.1"));
}
// 1.获取客户端ip地址( 这个必须从客户端传到后台):
// jsp页面下,很简单,request.getRemoteAddr() ;
// 因为系统的VIew层是用JSF来实现的,因此页面上没法直接获得类似request,在bean里做了个强制转换
// public String getMyIP() {
// try {
// FacesContext fc = FacesContext.getCurrentInstance();
// HttpServletRequest request = (HttpServletRequest) fc
// .getExternalContext().getRequest();
// return request.getRemoteAddr();
// } catch (Exception e) {
// e.printStackTrace();
// }
// return "";
// }
// 2.获取客户端mac地址
// 调用window的命令,在后台Bean里实现 通过ip来获取mac地址。方法如下:
// 运行速度【快】
public String getMAC() {
String mac = null;
try {
Process pro = Runtime.getRuntime().exec("cmd.exe /c ipconfig/all");
InputStream is = pro.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String message = br.readLine();
int index = -1;
while (message != null) {
if ((index = message.indexOf("Physical Address")) > 0) {
mac = message.substring(index + 36).trim();
break;
}
message = br.readLine();
}
System.out.println(mac);
br.close();
pro.destroy();
} catch (IOException e) {
System.out.println("Can't get mac address!");
return null;
}
return mac;
}
// 运行速度【慢】
public String getMAC(String ip) {
String str = null;
String macAddress = null;
try {
Process p = Runtime.getRuntime().exec("nbtstat -A " + ip);
InputStreamReader ir = new InputStreamReader(p.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for (; true;) {
str = input.readLine();
if (str != null) {
if (str.indexOf("MAC Address") > 1) {
macAddress = str
.substring(str.indexOf("MAC Address") + 14);
break;
}
}
}
} catch (IOException e) {
e.printStackTrace(System.out);
return null;
}
return macAddress;
}
}
2. Java web 怎么得到客户端的 Mac 地址
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
/*
* 物理地址是48位,别和ipv6搞错了
*/
public class LOCALMAC {
/**
* @param args
* @throws UnknownHostException
* @throws SocketException
*/
public static void main(String[] args) throws UnknownHostException, SocketException {
// TODO Auto-generated method stub
//得到IP,输出PC-201309011313/122.206.73.83
InetAddress ia = InetAddress.getLocalHost();
System.out.println(ia);
getLocalMac(ia);
}
private static void getLocalMac(InetAddress ia) throws SocketException {
// TODO Auto-generated method stub
//获取网卡,获取地址
byte[] mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress();
System.out.println("mac数组长度:"+mac.length);
StringBuffer sb = new StringBuffer("");
for(int i=0; i<mac.length; i++) {
if(i!=0) {
sb.append("-");
}
//字节转换为整数
int temp = mac[i]&0xff;
String str = Integer.toHexString(temp);
System.out.println("每8位:"+str);
if(str.length()==1) {
sb.append("0"+str);
}else {
sb.append(str);
}
}
System.out.println("本机MAC地址:"+sb.toString().toUpperCase());
}
}
3. C# web怎么获取手机的唯一标识,比如IMEI,Mac地址
WEB这东西,本来就是跨平台的东西,对于不同平台就有不同的浏览器,不同厂家的浏览器又不太一样。
尤其这种比较偏的底层接口。
2.就拿开发Android的WEB浏览器常用的WebView,就本身N个版本,接口改了又改。
你的网页还要跨平台,不管Android,还是WindowsPhone,适应于他们的变化有多复杂,自己要三思。
3.做那种混合型的App来让用户浏览自己的网站,内嵌WebView,通过JS和App交互,获取你需要的IMEI等等信息。
4.单纯Web页面是无法获取IMEI,除非W3C修订JavaScript标准,增加接口,并让浏览器厂商开始支持。
5.目前想获取IMEI,必须是app和Web页面相结合方式。
就如当前有个hbuilder开发工具,DCloud开发的。
6.可以调用手机系统API,原理类似于Java反射技术。
他们封装的比较好。可以直接通过js调用。
7.当然最后发布的不是真正的纯Web页面,是一个app安装包。
这里面的语法不是在任何浏览器都能运行的。
但发布的安装包,内部封装好的浏览器是可以支持相应的js方法。
8.web请求字段的UserAgent 段里只有操作系统版本,浏览器类型,浏览器内核版本这些信息,不会有其他信息。
9.至于ip,只要连接到web服务器,服务器就知道了,mac地址也是。
4. web程序不能获取mac地址吗
不能,WEB程序分为服务器语言写的程序和客户端语言写的程序,服务器脚本语言写的程序在客户端上是看不到的也无法访问,同样,服务器端通常也无法获取客户端的数据,当然也有通过客户端脚本语言挂载木马,然后通过下载木马到客户端然后获取数据的方法。。
5. 网站能否通过用户浏览获取用户的mac地址
当然可以获取用户的mac地址,你打开网站都会有脚本运行,在中国一般网站都会读取用户本地电脑上的信息,来做参考。
6. 怎样通过Web方式获得对方的网卡MAC地址
<%
strIP = Request.ServerVariables("REMOTE_ADDR")
strMac = GetMACAddress(strIP)
strHost = Request.ServerVariables("REMOTE_HOST")
Function GetMACAddress(strIP)
Set net = Server.CreateObject("wscript.network")
Set sh = Server.CreateObject("wscript.shell")
sh.run "%comspec% /c nbtstat -A " & strIP & " > c:" & strIP & ".txt",0,true
Set sh = nothing
Set fso = createobject("scripting.filesystemobject")
Set ts = fso.opentextfile("c:" & strIP & ".txt")
macaddress = null
Do While Not ts.AtEndOfStream
data = ucase(trim(ts.readline))
If instr(data,"MAC ADDRESS") Then
macaddress = trim(split(data,"=")(1))
Exit Do
End If
loop
ts.close
Set ts = nothing
fso.deletefile "c:" & strIP & ".txt"
Set fso = nothing
GetMACAddress = macaddress
End Function
%>
<HTML>
<HEAD>
<TITLE>Say Hello To the MAC MAN</TITLE>
</HEAD>
<BODY>
<%Response.Write("Your IP is : " & strIP & "<BR>" & vbcrlf)%>
<%Response.Write("Your MAC is : " & strMac & vbcrlf)%>
</BODY>
</HTML>
后记:此程序中需要USER_****用户有C盘的写入权限,也可以将文中的“C:”改为有写权限的驱动器(或目录)也可。
7. Java web 怎么得到客户端的Mac地址
importjava.net.InetAddress;
importjava.net.NetworkInterface;
importjava.net.SocketException;
importjava.net.UnknownHostException;
/*
*物理地址是48位,别和ipv6搞错了
*/
publicclassLOCALMAC{
/**
*@paramargs
*@throwsUnknownHostException
*@throwsSocketException
*/
publicstaticvoidmain(String[]args)throwsUnknownHostException,SocketException{
//TODOAuto-generatedmethodstub
//得到IP,输出PC-201309011313/122.206.73.83
InetAddressia=InetAddress.getLocalHost();
System.out.println(ia);
getLocalMac(ia);
}
privatestaticvoidgetLocalMac(InetAddressia)throwsSocketException{
//TODOAuto-generatedmethodstub
//获取网卡,获取地址
byte[]mac=NetworkInterface.getByInetAddress(ia).getHardwareAddress();
System.out.println("mac数组长度:"+mac.length);
StringBuffersb=newStringBuffer("");
for(inti=0;i<mac.length;i++){
if(i!=0){
sb.append("-");
}
//字节转换为整数
inttemp=mac[i]&0xff;
Stringstr=Integer.toHexString(temp);
System.out.println("每8位:"+str);
if(str.length()==1){
sb.append("0"+str);
}else{
sb.append(str);
}
}
System.out.println("本机MAC地址:"+sb.toString().toUpperCase());
}
}
8. java web 获取当前登陆用户的MAC地址,但是报异常了!!!
java代码是运行在服务器端的,你要获得客户端的mac地址只能用js实现