在做B/S結構的系統時,我們常常需要取得客戶端的一些信息,如IP和MAC,以結合身份驗證。要取得伺服器端的MAC很容易,但是要取得客戶端的MAC的位址確要花費一翻心思,通常的做法是呼叫Win32API或直接呼叫nbtstat指令,這樣做有很多問題,而另一種方法就是直接用客戶端腳本,我們這裡用Javascript,這樣做的好處是不需要伺服器端進行處理,有客戶端自行獲取,傳遞到伺服器端,且速度和可靠性都比在伺服器端取得好。 實作的html和javascript如下: 複製程式碼複製程式碼 程式碼 🎜> WMI Scripting HTML <BR>document.forms[0].txtMACAddr.value=unescape(MACAddr); <form. [0].txtIPAddr.value=unescape(IPAddr); <BR>document.forms[0].txtDNSName.value=unescape(sDNSName); <BR>//document.formbar.submit(); <BR></ SCRIPT> <BR><SCRIPT language=JScript event=OnObjectReady(objObject,objAsyncContext) for=foo> <BR>if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" & EnabledobjObject.IPEnabled != "undefined" & peobjObject.IPEnabled != "undefined" & peobjObject.IPEnabled != "undefined" & peobjObject.IPEnabled != "undefined" & peobjObject.IPEnabled != "undefined" & peobjObject.IPEnabled != "undefined" & objObject.IPEnabled != "undefined" & peobjObject. <BR>{ <BR>if(objObject.MACAddress != null && objObject.MACAddress != "undefined") <BR>MACAddr = objObject.MACAddress; <BR>if(objObject.IPEnabled && objObject.IPAddress(objObject.IPEnabled && ob = null && objObject.IPAddress(0) != "undefined") <BR>IPAddr = objObject.IPAddress(0); <BR>if(objObject.DNSHostName != null && objObject. >sDNSName = objObject.DNSHostName; <BR>} <BR>