function |mac| Network card
How to read the NIC MAC address through ASP? The basic ASP platform to read MAC addresses requires two system-critical component support, "WSCRIPT." SHELL "and" Scripting.FileSystemObject "two components, however, the opening of these two components is quite dangerous, because a lot of virus script is through them to control the host permissions, in the use of this feature, should pay attention to security precautions.
Due to read the NIC MAC address of an IP
This program reads the MAC address of a specific IP by querying the native ARP table by invoking the ARP command
The use of this program should pay attention to the following matters:
This procedure requires "WSCRIPT." SHELL "and" Scripting.FileSystemObject "two components, make sure that your server can use both components properly
This program needs to call the Cmd.exe program, please make sure that the IIS Guest account has access to the program.
This program requires temporary file save results, please make sure that the IIS Guest account has write permission to the temp directory.
The function code is as follows:
The following is the ASP code: ' Source: Arisisi alixixi.com Public Function Getmac (IP) On Error Resume Next Dim Oscript Dim Ofilesys, Ofile Dim all, Sztempfile,ipc,phyc,typec Dim TempPath Set oscript = Server.CreateObject ("WSCRIPT. SHELL ") Set Ofilesys = Server.CreateObject ("Scripting.FileSystemObject") Temppath= "d:\temp\" temporary Directory Sztempfile = TempPath & Ofilesys.gettempname () ' Get temporary file name Call Oscript.run ("cmd.exe/c ping-n 2" & IP, 0, True) ' guarantees that this IP is in the ARP table Call Oscript.run ("cmd.exe/c arp-a" & IP & ">" & Sztempfile, 0, True) Set ofile = Ofilesys.opentextfile (sztempfile, 1, False, 0) All=ofile.readall () Ofile.close If (IsObject (ofile)) Then Call Ofilesys.deletefile (Sztempfile, True) End If arr = Split (all, vbCrLf) If UBound (arr) = 4 Then IPC = INSTR (1, arr (2), "Internet address") PHYC = InStr (1, arr (2), "Physical Address") Typec = InStr (1, arr (2), "Type") If typec > PHYC and PHYC > IPC and IPC > 0 Then Getmac=ucase (Trim (CStr (arr (3), PHYC, TYPEC-PHYC))) End If End If End Function |