Obtain network information such as the MAC address and DNS address of the server Nic in ASP.

Source: Internet
Author: User

Due to the development of a MIS system some time ago, the MIS is a non-free software, so the corresponding registration module must be developed when the system is developed, because it is a B/S system, I chose a unique Nic MAC address for the pattern registration. If you have less time to talk about it, let's get into the question below. Because the system is a commercial software, the following code only contains the code idea and simple implementation code. For details, you can freely use the code or share it with me.

---------------------- Extract information of all NICs --------------------'

Public Function getmacinfo ()
On Error resume next

Dim FSO, filestr, aspsleepthread, inclustr, Sysdir, wshshell, cmsid, macfilecontentfile, macfilecontent
Const MacFile = "tmpyesoulsoft001.llp"
Set FSO = server. Createobject ("scripting. FileSystemObject ")

Sysdir = Split (globalmod. getsysdir, ",") (1)
If instr (lcase (Sysdir), "System32") = 0 then
Getmacinfo = "this system can only run in 32-bit systems, such as NT, Windows 2000, Windows. net, Windows XP, and Windows 2003. It does not support 32-bit or lower systems! "
'Www .knowsky.com
Exit Function
Else
Using STR = Sysdir + "/cmd.exe/C" + Sysdir + "/ipconfig.exe/All>" + server. mappath (MacFile)
End if
Cmsid = shell (reverse STR, vbhide)
If cmsid <> 0 then
Set macfilecontentfile = FSO. opentextfile (server. mappath (MacFile), 1, false, tristateusedefault)
'Getmacinfo = macfilecontentfile. readall ()
'Response. Flush
Filestr = macfilecontentfile. readall ()
Macfilecontentfile. Close
Set macfilecontentfile = nothing
Set aspsleepthread = server. Createobject ("yesoulsoft. sleepthread ")
'Defines the thread suspension time, in milliseconds.
Aspsleepthread. sleeptime = 500
Aspsleepthread. beginsleepthread
Getmacinfo = executeone (filestr, "physical address .........:(.*)")
Set aspsleepthread = nothing
Else
Getmacinfo = "the system cannot obtain your network information currently. Check the permission inheritance relationship before running the system! "
Exit Function
End if
Delfile MacFile

Set FSO = nothing

End Function
'------------------ Match the result in a string -------------------'
Public Function executeone (inpstr, patstr)
Dim ore, omatch, omatches
Set ORE = new Regexp
Ore. pattern = patstr
Inpstr = lcase (inpstr)
Ore. ignorecase = true
Set omatches = ore. Execute (inpstr)
Set omatch = omatches (0)
Executeone = omatch. submatches (0)
End Function

In the code, the getmacinfo function can only obtain the MAC address of the first Nic. You can refer to DNS, gateway, and other information.

 

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: info-contact@alibabacloud.com 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.