ASP gets the MAC address of the NIC

Source: Internet
Author: User
Tags exit integer
<% Option explicit%>

<%
Private Const Ncbastat = &h33
Private Const Ncbnamsz = 16
Private Const heap_zero_memory = &h8
Private Const heap_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 Integer
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 as Integer
End Type
Private Type Astat
Adapt as Adapter_status
Namebuff () 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 Then
getmacaddress = "Invalid IP address."
Exit Function
End If

For x = 0 to UBound (AIP ())
If Len (AIP (x)) > 3 Then
getmacaddress = "Invalid IP address"
Exit Function
End If

If IsNumeric (AIP (x)) = False Then
getmacaddress = "Invalid IP address"
Exit Function
End If

If InStr (AIP (x), ",") <> 0 Then
getmacaddress = "Invalid IP address"
Exit Function
End If

If CLng (AIP (x)) > 255 Then
getmacaddress = "Invalid IP address"
Exit Function
End If

If NIP = "" Then
NIP = String (3-len (AIP (x)), "0") & AIP (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



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: 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.