ASP obtains the client MAC address (source code)

Source: Internet
Author: User
Tags servervariables

BenProgramIs a special method. The scope of use is relatively limited, and there is a certain risk. Some methods in ASP backdoors are used for reference. Below is the programCode.


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 ))

'The MAC address of the NIC that reads an IP address

'The program reads the MAC address of a specific IP address from the local ARP table by calling the ARP command.

'Note the following when using this program:

'The program requires two components: "wscript. Shell" and "scripting. FileSystemObject". Make sure that your server can use these two components normally.

'The local program uses the cmd.exe program. Make sure that the IIS Guest Account has permission to access the program.

'This program requires temporary files to save the results. Make sure that the IIS Guest account has the write permission on the temporary 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 the temporary file name

Call oscript. Run ("cmd.exe/c Ping-N 2" & IP, 0, true) 'ensure that this IP address exists 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 (mid (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.