這裡蒐索程式師資訊,查找有用的技術資料
當前位置:首頁 » 網頁前端 » web獲取客戶端mac地址
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

web獲取客戶端mac地址

發布時間: 2022-10-10 09:33:10

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這東西,本來就是跨平台的東西,對於不同平台就有不同的瀏覽器,不同廠家的瀏覽器又不太一樣。

  1. 尤其這種比較偏的底層介面。

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實現