* Written by Jaron, 2003-11-21 * // * original: 9CBS document center http://www.9cbs.net/develop Web technology 中文 网 http://www.jaron.cn * // * Reprint Note and retain this copyright information * // * Welcome to the SiteManager-CMS Server website management system http://siteManager.cnzone.net * // * Detect Mac Component (ACTIVEX DLL) source code / * In ASP, Get the server's current network card address by self-writing components
Option expedition
Private const ncbastat = & h33 private const ncbnamsz = 16 private constheap_zero_memory = & h8 private constheap_generate_exceptions = & h4 private const ncbreset = & h32
Private Type NCB ncb_command As Byte 'Integer ncb_retcode As Byte' Integer ncb_lsn As Byte 'Integer ncb_num As Byte' Integer ncb_buffer As Long 'String ncb_length As Integer ncb_callname As String * NCBNAMSZ ncb_name As String * NCBNAMSZ ncb_rto As Byte' Integer ncb_sto As Byte ' Integer ncb_post As Long ncb_lana_num As Byte 'Integer ncb_cmd_cplt As Byte' Integer ncb_reserve (9) As Byte 'Reserved, must be 0 ncb_event As Long End Type Private Type ADAPTER_STATUS adapter_address (5) As Byte' As String * 6 rev_major As Byte 'Integer reserved0 As Byte 'Integer adapter_type As Byte' Integer rev_minor As Byte 'Integer duration As Integer frmr_recv As Integer frmr_xmit As Integer iframe_recv_err As Integer xmit_aborts As Integer xmit_success As Long recv_success As Long iframe_xmit_err As Intege r recv_buff_unavail As Integer t1_timeouts As Integer ti_timeouts As Integer Reserved1 As Long free_ncbs As Integer max_cfg_ncbs As Integer max_ncbs As Integer xmit_buf_unavail As Integer max_dgram_size As Integer pending_sess As Integer max_cfg_sess As Integer max_sess As Integer max_sess_pkt_size As Integer name_count As Integer End Type Private Type NAME_BUFFER name As String * ncbnamsz name_num as integer name_flags asset adapt as adapter_status namebuff (30) AS name_buffer end type
Private Declare Function Netbios Lib "netapi32.dll" _ (pncb As NCB) As Byte Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (_ hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long) Private Declare Function GetProcessHeap lib "kernel32" () As Long Private Declare Function HeapAlloc lib "kernel32" _ (ByVal hHeap As Long, ByVal dwFlags As Long, _ ByVal dwBytes As Long) As Long Private Declare Function HeapFree lib "kernel32" (ByVal hHeap As Long, _BYVAL DWFLAGS AS Long, LPMEM AS ANY) AS Long
Public Function GetMACAddress (sIP As String) As String Dim sRtn As String Dim myNcb As NCB Dim bRet As Byte Dim aIP () As String Dim x As Long Dim nIP As String If InStr (sIP, ".") = 0 Then GetMACAddress = "Invalid IP Address." EXIT FUNCTION END IF AIP = Split (SIP, ", -1, VbtextCompare) IF Ubound (AIP ()) <> 3 Ten getMacaddress =" invalid IP address. "EXIT FUNCTION END IF For x = 0 to Ubound (AIP ())> 3 Ten GetMacaddress = "Invalid IP Address" EXIT FUNCTION END IF ISNUMERIC (AIP (X)) = false dam getMacaddress = "invalid IP address "EXIT FUNCTION END IF INSTR (AIP (X),", ") <> 0 Then getMacaddress =" Invalid IP Address "EXIT FUNCTION END IF CLNG (AIP (X))> 255 Ten getMacadDress =" invalid IP address "exit function end if if nip =" "" "" "0"), "0") & A IP (x) else nip = NIP & "." & String (3 - len (AIP (X)), "0") & AIP (x) end if Next
sRtn = "" myNcb.ncb_command = NCBRESET bRet = Netbios (myNcb) myNcb.ncb_command = NCBASTAT myNcb.ncb_lana_num = 0 myNcb.ncb_callname = nIP & Chr (0) Dim myASTAT As ASTAT, tempASTAT As ASTAT Dim pASTAT As Long myNcb.ncb_length = Len (myASTAT) pASTAT = HeapAlloc (GetProcessHeap (), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, myNcb.ncb_length) If pASTAT = 0 Then getMACAddress = "memory allcoation failed!" Exit Function End IfmyNcb.ncb_buffer = pASTAT bRet = Netbios (myNcb)
If BRET <> 0 Then getMacaddress = "Cannot get Mac from the current IP address, current IP address:" & SIP EXIT FUNCTION END IF COPYMEMORY MyAstat, MYNCB.NCB_BUFFER, LEN (MyAstat) DIM STEMP AS STRING DIM I as Long for i = 0 TO 5 STEMP = HEX (myastat.adapt.adapter_address (i)) IF i = 0 THEN SRTN = IIF (LEN (STEMP) <2, "0" & STEMP, STEMP ELSE SRTN = SRTN & SPACE (1) & IIF (Len (STEMP) <2, "0" & STEMP, STEMP) End HeapFree getProcessHeap (), 0, Pastat getMacaddress = SRTNEND FUNCTION
Instructions:
SET S_MAC = Server.createObject ("Engineen name. Class name") response.write s_mac.getmacaddress (Request.ServerVariables ("remote_host") SET S_MAC = Nothing