新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论.NET,C#,ASP,VB技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机技术与应用『 Dot NET,C#,ASP,VB 』 → ASP获得网卡的MAC地址 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 5594 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: ASP获得网卡的MAC地址 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     Qr 帅哥哟,离线,有人找我吗?
      
      
      威望:9
      等级:博士二年级(版主)
      文章:4392
      积分:29981
      门派:XML.ORG.CN
      注册:2004/5/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Qr发送一个短消息 把Qr加入好友 查看Qr的个人资料 搜索Qr在『 Dot NET,C#,ASP,VB 』的所有贴子 访问Qr的主页 引用回复这个贴子 回复这个贴子 查看Qr的博客楼主
    发贴心情 ASP获得网卡的MAC地址

    <% 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(30) 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 = "无效的IP地址."
    Exit Function
    End If

    aIP = Split(sIP, ".", -1, vbTextCompare)
    If UBound(aIP()) <> 3 Then
    GetMACAddress = "无效的IP地址."
    Exit Function
    End If

    For x = 0 To UBound(aIP())
    If Len(aIP(x)) > 3 Then
    GetMACAddress = "无效的IP地址"
    Exit Function
    End If

    If IsNumeric(aIP(x)) = False Then
    GetMACAddress = "无效的IP地址"
    Exit Function
    End If

    If InStr(aIP(x), ",") <> 0 Then
    GetMACAddress = "无效的IP地址"
    Exit Function
    End If

    If CLng(aIP(x)) > 255 Then
    GetMACAddress = "无效的IP地址"
    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
    myNcb.ncb_callname = nIP & Chr(0)

    Dim myASTAT As ASTAT, tempASTAT As ASTAT
    Dim pASTAT As Long
    myNcb.ncb_length = Len(myASTAT)

    pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, myNcb.ncb_length)
    If pASTAT = 0 Then
    GetMACAddress = "memory allcoation failed!"
    Exit Function
    End If

    myNcb.ncb_buffer = pASTAT
    bRet = Netbios(myNcb)

    If bRet <> 0 Then
    GetMACAddress = "不能从当前IP地址获得MAC,当前IP地址: " & sIP
    Exit Function
    End If

    CopyMemory myASTAT, myNcb.ncb_buffer, Len(myASTAT)

    Dim sTemp As String
    Dim i As Long
    For i = 0 To 5
    sTemp = Hex(myASTAT.adapt.adapter_address(i))
    If i = 0 Then
    sRtn = IIf(Len(sTemp) < 2, "0" & sTemp, sTemp)
    Else
    sRtn = sRtn & Space(1) & IIf(Len(sTemp) < 2, "0" & sTemp, sTemp)
    End If
    Next
    HeapFree GetProcessHeap(), 0, pASTAT
    GetMACAddress = sRtn
    End Function
    %>
    <%
    set S_MAC = server.CreateObject( "adodb.recordset")
    response.write S_MAC.GetMACAddress(Request.Servervariables("REMOTE_HOST"))
    set S_MAC = nothing
    %>


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    没人帮忙,那就靠自己,自己才是最好的老师!本人拒绝回答通过站内短消息提出的问题!

    blog:http://Qr.blogger.org.cn

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/1/20 17:28:00
     
     xmzhy 帅哥哟,离线,有人找我吗?狮子座1978-8-18
      
      
      威望:5
      等级:计算机学士学位
      文章:385
      积分:2003
      门派:XML.ORG.CN
      注册:2003/10/22

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给xmzhy发送一个短消息 把xmzhy加入好友 查看xmzhy的个人资料 搜索xmzhy在『 Dot NET,C#,ASP,VB 』的所有贴子 引用回复这个贴子 回复这个贴子 查看xmzhy的博客2
    发贴心情 
    收集
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/1/21 11:08:00
     
     GoogleAdSense狮子座1978-8-18
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Dot NET,C#,ASP,VB 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/10 11:48:06

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    66.406ms