ASP get client MAC address (source code)

Source: Internet
Author: User
Tags iis servervariables client
Client | source code

This procedure belongs to a special method. The scope of use is relatively limited, and there is a certain risk. Borrowed from the ASP in the back door of some methods. The following is the program code.


Dim remoteaddr

If Request.ServerVariables ("Http_x_forwarded_for") =empty Then

Remoteaddr=request.servervariables ("REMOTE_ADDR")


Remoteaddr=request.servervariables ("Http_x_forwarded_for")

End If

Response.Write (Getmac (REMOTEADDR))

' 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 calling the ARP command

' Use of this program should be aware of the following matters:

' This procedure needs ' 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 procedure requires temporary file save results, please make sure that the IIS Guest account has write permission to the temp directory.


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 ("cmd.exe/c ping-n 2" & IP, 0, True) ' guarantees that this IP is in the ARP table

Call ("cmd.exe/c arp-a" & IP & ">" & Sztempfile, 0, True)

Set ofile = Ofilesys.opentextfile (sztempfile, 1, False, 0)

All=ofile.readall ()


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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.