CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  ASP

用asp取客户机mac地址的问题!

楼主syd41()2005-04-03 09:32:30 在 Web 开发 / ASP 提问

最近在做一个测试,想通过服务器返回客户端的MAC地址,可一直没有找到解决的好办法……  
   
  在这里想通过CSDN技术论坛向各位高手们请教一下:如何用asp取客户机mac地址? 问题点数:50、回复次数:13Top

1 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2005-04-03 09:39:25 得分 20

调用对方的wmiTop

2 楼ffyd2000(卡拉永遠OK)回复于 2005-04-03 09:39:40 得分 0

UP,高手来帮忙,我来学习Top

3 楼CXL_2005(想飞的笨笨)回复于 2005-04-03 10:47:51 得分 0

up  
  学习Top

4 楼yb2008(中科商务网--ZKE360.COM)回复于 2005-04-03 11:04:56 得分 30

<%@   LANGUAGE="VBSCRIPT"%>  
  <%      
  strIP   =   Request.ServerVariables("REMOTE_ADDR")      
  strMac   =   GetMACAddress(strIP)      
  strHost     =   Request.ServerVariables("REMOTE_HOST")      
   
  Function   GetMACAddress(strIP)      
  Set   net   =     Server.CreateObject("wscript.network")      
      Set   sh   =     Server.CreateObject("wscript.shell")      
  sh.run   "%comspec%   /c   nbtstat   -A   "   &   strIP   &   ">   c:\"   &   strIP   &   ".txt   ",0,true      
  Set   sh   =   nothing      
  Set   fso   =   createobject("scripting.filesystemobject")      
      Set   ts   =   fso.opentextfile("c:\"   &   strIP   &   ".txt")      
  macaddress   =   null      
  Do   While   Not   ts.AtEndOfStream  
  data   =   ucase(trim(ts.readline))      
  If   instr(data,"MAC   ADDRESS")   Then      
  macaddress   =   trim(split(data,"=")(1))      
  Exit   Do      
  End   If      
  loop      
  ts.close      
      Set   ts   =   nothing      
      fso.deletefile   "c:\"   &   strIP   &   ".txt"      
      Set   fso   =   nothing      
  GetMACAddress   =   macaddress      
  End   Function          
  %>      
  <HTML>      
  <HEAD>      
  <TITLE>Say   Hello   To   the   MAC   MAN   </TITLE>      
  </HEAD>      
  <BODY>      
  <%Response.Write("Your   IP   is:"   &   strIP   &   "   "   &   vbcrlf)%>      
  <%Response.Write("Your   MAC   is:"   &   strMac   &   vbcrlf)%>      
  </BODY>      
  </HTML>Top

5 楼gmlwl(笨笨猫)回复于 2005-04-03 11:15:29 得分 0

我正好也需要这个呵,谢谢楼上兄弟.Top

6 楼crazysoul(crazy)回复于 2005-04-03 11:15:36 得分 0

楼上的这个是取服务端的.  
  客户端的这个问题我也想过,由于权限问题,不能用一般的WEB来实现,只能让客户端下载控件执行这种方式.否则就得像HACKER一样找漏洞写代码,呵呵.Top

7 楼syd41()回复于 2005-04-03 12:10:43 得分 0

在这里先谢谢   yb2008(努力学ASP.NET!!)   的大力支持  
   
  但是楼上所说的问题,不知道需要怎样的权限才能解决此问题?Top

8 楼daddi(天苍苍)回复于 2005-04-03 13:17:41 得分 0

让客户下载是做得到的,但是让客户下载的这个客户端程序应该怎么写呢?Top

9 楼lstup(流水)回复于 2005-04-03 13:29:01 得分 0

关注,短期内也许也会用到Top

10 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2005-04-03 13:33:50 得分 0

activex写这个非常简单  
   
  下面这代码可以做成控件的形式?嵌入网页后,通过asp调用读取客户端网卡mac地址,请各位前辈多多帮忙,告诉怎么做,我是一个初学者,有急用,谢谢!!!  
   
  Option   Explicit    
   
  Public   Const   NCBASTAT   As   Long   =   &H33    
  Public   Const   NCBNAMSZ   As   Long   =   16    
  Public   Const   HEAP_ZERO_MEMORY   As   Long   =   &H8    
  Public   Const   HEAP_GENERATE_EXCEPTIONS   As   Long   =   &H4    
  Public   Const   NCBRESET   As   Long   =   &H32    
   
  Public   Type   NET_CONTROL_BLOCK   'NCB    
  ncb_command   As   Byte    
  ncb_retcode   As   Byte    
  ncb_lsn   As   Byte    
  ncb_num   As   Byte    
  ncb_buffer   As   Long    
  ncb_length   As   Integer    
  ncb_callname   As   String   *   NCBNAMSZ    
  ncb_name   As   String   *   NCBNAMSZ    
  ncb_rto   As   Byte    
  ncb_sto   As   Byte    
  ncb_post   As   Long    
  ncb_lana_num   As   Byte    
  ncb_cmd_cplt   As   Byte    
  ncb_reserve(9)   As   Byte   '   Reserved,   must   be   0    
  ncb_event   As   Long    
  End   Type    
   
  Public   Type   ADAPTER_STATUS    
  adapter_address(5)   As   Byte    
  rev_major   As   Byte    
  reserved0   As   Byte    
  adapter_type   As   Byte    
  rev_minor   As   Byte    
  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    
  End   Type    
   
  Public   Type   NAME_BUFFER    
  name   As   String   *   NCBNAMSZ    
  name_num   As   Integer    
  name_flags   As   Integer    
  End   Type    
   
  Public   Type   ASTAT    
  adapt   As   ADAPTER_STATUS    
  NameBuff(30)   As   NAME_BUFFER    
  End   Type    
   
  Public   Declare   Function   Netbios   Lib   "netapi32.dll"   _    
  (pncb   As   NET_CONTROL_BLOCK)   As   Byte    
   
  Public   Declare   Sub   CopyMemory   Lib   "kernel32"   Alias   "RtlMoveMemory"   _    
  (hpvDest   As   Any,   ByVal   _    
  hpvSource   As   Long,   ByVal   _    
  cbCopy   As   Long)    
   
  Public   Declare   Function   GetProcessHeap   Lib   "kernel32"   ()   As   Long    
   
   
  Public   Declare   Function   HeapAlloc   Lib   "kernel32"   _    
  (ByVal   hHeap   As   Long,   ByVal   dwFlags   As   Long,   _    
  ByVal   dwBytes   As   Long)   As   Long    
   
  Public   Declare   Function   HeapFree   Lib   "kernel32"   _    
  (ByVal   hHeap   As   Long,   _    
  ByVal   dwFlags   As   Long,   _    
  lpMem   As   Any)   As   Long    
   
   
  Public   Function   GetMACAddress()   As   String    
   
  'retrieve   the   MAC   Address   for   the   network   controller    
  'installed,   returning   a   formatted   string    
   
  Dim   tmp   As   String    
  Dim   pASTAT   As   Long    
  Dim   NCB   As   NET_CONTROL_BLOCK    
  Dim   AST   As   ASTAT    
   
  'The   IBM   NetBIOS   3.0   specifications   defines   four   basic    
  'NetBIOS   environments   under   the   NCBRESET   command.   Win32    
  'follows   the   OS/2   Dynamic   Link   Routine   (DLR)   environment.    
  'This   means   that   the   first   NCB   issued   by   an   application    
  'must   be   a   NCBRESET,   with   the   exception   of   NCBENUM.    
  'The   Windows   NT   implementation   differs   from   the   IBM    
  'NetBIOS   3.0   specifications   in   the   NCB_CALLNAME   field.    
  NCB.ncb_command   =   NCBRESET    
  Call   Netbios(NCB)    
   
  'To   get   the   Media   Access   Control   (MAC)   address   for   an    
  'ethernet   adapter   programmatically,   use   the   Netbios()    
  'NCBASTAT   command   and   provide   a   "*"   as   the   name   in   the    
  'NCB.ncb_CallName   field   (in   a   16-chr   string).    
  NCB.ncb_callname   =   "*   "    
  NCB.ncb_command   =   NCBASTAT    
   
  'For   machines   with   multiple   network   adapters   you   need   to    
  'enumerate   the   LANA   numbers   and   perform   the   NCBASTAT    
  'command   on   each.   Even   when   you   have   a   single   network    
  'adapter,   it   is   a   good   idea   to   enumerate   valid   LANA   numbers    
  'first   and   perform   the   NCBASTAT   on   one   of   the   valid   LANA    
  'numbers.   It   is   considered   bad   programming   to   hardcode   the    
  'LANA   number   to   0   (see   the   comments   section   below).    
  NCB.ncb_lana_num   =   0    
  NCB.ncb_length   =   Len(AST)    
   
  pASTAT   =   HeapAlloc(GetProcessHeap(),   HEAP_GENERATE_EXCEPTIONS   _    
  Or   HEAP_ZERO_MEMORY,   NCB.ncb_length)    
   
  If   pASTAT   =   0   Then    
  Debug.Print   "memory   allocation   failed!"    
  Exit   Function    
  End   If    
   
  NCB.ncb_buffer   =   pASTAT    
  Call   Netbios(NCB)    
   
  CopyMemory   AST,   NCB.ncb_buffer,   Len(AST)    
   
  tmp   =   Format$(Hex(AST.adapt.adapter_address(0)),   "00")   &   "   "   &   _    
  Format$(Hex(AST.adapt.adapter_address(1)),   "00")   &   "   "   &   _    
  Format$(Hex(AST.adapt.adapter_address(2)),   "00")   &   "   "   &   _    
  Format$(Hex(AST.adapt.adapter_address(3)),   "00")   &   "   "   &   _    
  Format$(Hex(AST.adapt.adapter_address(4)),   "00")   &   "   "   &   _    
  Format$(Hex(AST.adapt.adapter_address(5)),   "00")    
   
   
  HeapFree   GetProcessHeap(),   0,   pASTAT    
   
  GetMACAddress   =   tmp    
   
  End   Function    
  '--end   block--'    
   
  用google搜索一大把呢,楼主跟我的几个短消息,回一下了,不过楼主是男的,下回不用说是小妹的Top

11 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2005-04-03 13:33:56 得分 0

Form   Code    
   
  To   a   form   add   a   command   button   (Command1),   and   a   text   box   (Text1).   Labels   and    
  frames   are   optional.   Add   the   following   to   the   command   button:    
   
  ------------------------------------------------------------------------------    
  --    
   
   
  Option   Explicit    
   
  Private   Sub   Command1_Click()    
   
  Text1   =   GetMACAddress()    
   
  End   Sub    
  '--end   block--'    
   
   
  Comments    
   
  Other   hardware   and   software   may   be   assigned   their   own   MAC   addresses.   For    
  example,   a   modem   can   have   a   MAC   address.   Also,   a   RAS   client   or   server   can    
  install   "dummy"   network   adapters   that   correspond   to   a   dialup   or   serial    
  connection.   Normally,   these   MAC   addresses   are   randomly   generated.   If   an    
  adapter   status   is   called   on   a   LANA   that   corresponds   to   one   of   these   adapters    
  when   no   connection   is   present,   Netbios   returns   error   0x34   (NRC_ENVNOTDEF)    
  even   if   a   reset   was   previously   performed.    
  With   the   NetBEUI   and   IPX   transports,   the   same   information   can   be   obtained   at    
  a   command   prompt   by   using:    
   
  net   config   workstation    
   
  The   ID   given   is   the   MAC   address.    
   
  How   to   Use   LANA   Numbers   in   a   32-bit   Environment    
  Last   reviewed:   August   7,   1996    
  Article   ID:   Q138037    
  The   information   in   this   article   applies   to:    
  Microsoft   Win32   Software   Development   Kit   (SDK)   versions   3.1,   3.5,   3.51,   4.0    
   
  SUMMARY    
  NetBIOS   uses   the   concept   of   a   LANA   (LAN   adapter   number)   that   allows   you   to    
  write   transport-independent   NetBIOS   applications.   This   article   describes   what    
  a   LANA   is   and   recommends   an   approach   to   writing   NetBIOS   applications.    
   
  MORE   INFORMATION    
  A   LANA   is   a   field   of   the   NetBIOS   NCB   structure.   In   IBM's   NetBIOS   3.0    
  specification,   a   LANA   was   used   to   specify   a   particular   network   adapter,   as    
  NetBIOS   then   supported   up   to   two   network   adapters   in   one   PC   computer.    
  Specifying   a   LANA   of   zero   directed   a   request   to   the   first   adapter,   and    
  specifying   a   LANA   of   one   directed   a   request   to   the   second   adapter.    
   
  Originally,   IBM   sent   NetBIOS   packets   over   the   NetBEUI   protocol,   also   known   as    
  the   NetBIOS   Frames   protocol.   This   was   the   only   transport   NetBIOS   could   use   to    
  send   data   across   the   network.   In   other   words,   each   network   adapter   had   only    
  one   protocol   to   send   and   receive   NetBIOS   packets.    
   
  Because   most   computers   have   only   one   network   adapter,   many   MS-DOS-based    
  applications   send   all   their   requests   to   a   LANA   value   of   zero   (also   called    
  simply   'LANA   zero').   If   a   second   network   adapter   is   installed,   some   programs    
  allow   the   user   to   configure   the   application   to   use   LANA   one   instead.   As   a    
  result,   LANA   zero   became   a   default   setting,   though   it   was   never   intended   to    
  be   a   default.    
   
  Today's   network   technology   allows   NetBIOS   to   use   transports   other   than    
  NetBEUI.   Microsoft   has   extended   the   meaning   of   LANA   to   indicate   a   specific    
  transport   on   a   specific   adapter.   For   example,   if   you   have   two   network    
  adapters,   and   have   IPX/SPX   and   NetBEUI   transports   installed,   you   have   four    
  LANAs.   The   LANAs   may   or   may   not   be   sequential,   and   there   is   no   systematic   way    
  to   identify   which   transport   maps   to   which   LANA.    
   
  In   addition   to   extending   the   meaning   of   a   LANA,   Microsoft   also   added   an   NCB    
  command   (NCBENUM)   that   returns   an   array   of   available   LANA   numbers.   As   an    
  example,   the   LANA_ENUM   structure   filled   by   NCBENUM   might   hold   an   array   with    
  values   0,   3,   5,   and   6.   Zero   might   map   to   IPX/SPX   on   the   first   adapter,   three    
  might   map   to   NETBEUI   on   a   second   adapter,   and   so   on.    
   
   
  In   Windows   NT   and   Windows   95,   network   adapters   consist   of   physical   adapters    
  (like   a   3Com   Etherlink   II)   and   software   adapters   (like   the   Dial   Up   Adapter).    
  In   addition,   a   user   may   have   TCP/IP,   NETBEUI,   IPX/SPX,   and   other   transports    
  installed,   all   of   which   have   NetBIOS   support.    
   
  For   Windows   NT,   LANAs   are   configurable   through   the   control   panel.   Choose   the    
  Network   applet,   choose   the   NetBIOS   Interface   component,   then   choose    
  Configure.   A   dialog   appears   that   allows   you   to   edit   the   LANAs.    
   
  For   Windows   95,   you   may   only   set   LANA   zero,   the   default   protocol,   and   if   no    
  protocol   is   set   as   default,   there   won't   be   a   LANA   zero.   You   can   set   the    
  default   protocol   in   the   control   panel.   Choose   the   Network   applet,   choose   the    
  protocol   you   want   as   default,   choose   Properties,   the   Advanced   tab,   and    
  finally   check   'Set   this   protocol   to   be   the   default   protocol'.    
   
  LANAs   may   seem   like   a   constraint   that   your   application   must   work   around.    
  However,   making   your   application   ignorant   of   how   users   want   to   configure    
  their   machines   is   a   powerful   idea,   and   one   that   makes   life   easier   for   your    
  customers.    
   
  The   best   way   to   write   a   NetBIOS   application   is   to   support   all   LANAs,   and    
  establish   connections   over   any   LANA.   A   good   approach   is   outlined   in   the    
  following   steps:    
   
  Enumerate   the   LANAs   by   submitting   NCBENUM.    
  Reset   each   LANA   by   submitting   one   NCBRESET   per   LANA.    
  Add   your   local   NetBIOS   name   to   each   LANA.   The   name   may   be   the   same   on   each    
  LANA.    
  Connect   using   any   LANA:    
  For   servers,   submit   an   NCBLISTEN   on   each   LANA.   If   necessary,   cancel   any    
  outstanding   listen   after   the   first   listen   is   satisfied.    
  For   clients,   submit   an   NCBFINDNAME   (Windows   NT   only)   or   an   NCBCALL   (either    
  Windows   NT   or   Windows   95)   on   each   LANA.   The   first   successful   find   name   or    
  call   will   indicate   which   LANA   to   use.   When   using   NCBCALL   instead   of    
  NCBFINDNAME,   you   must   cancel   any   pending   NCBCALLs   and   hang   up   the   extra    
  completed   calls   (when   two   or   more   calls   are   successful.)    
  It   is   a   good   idea   to   submit   NCBADDNAME,   NCBLISTEN,   NCBFINDNAME,   and   NCBCALL    
  asynchronously.   Asynchronous   requests   will   be   processed   almost   in   parallel   on    
  each   transport.    
   
  This   architecture   is   quite   beneficial.   Once   your   application   is   written   to    
  establish   connections   in   this   manner,   it   will   support   any   transport   that    
  NetBIOS   can   use.   As   a   result,   your   customers   will   not   have   to   configure    
  anything   within   your   application,   and   your   application   will   not   be   affected    
  by   dynamic   LANAs   such   as   dial-up   adapters   or   plug-and-play   hardware.Top

12 楼lstup(流水)回复于 2005-04-03 13:35:09 得分 0

ASP获取客户端MAC地址         [   2005-02-11   3:35:00   PM   |   Author:   callcall   |   From:   Original   |   Online:   301   ]         【首页】      
  本程序属于一种特别的方法。使用范围比较有限,而且有一定的危险性。借鉴了asp后门里的一些方法。下面是程序代码。  
   
  <%  
  dim   remoteaddr  
  if   Request.ServerVariables("HTTP_X_FORWARDED_FOR")=empty   then  
  remoteaddr=Request.ServerVariables("REMOTE_ADDR")  
  else  
  remoteaddr=Request.ServerVariables("HTTP_X_FORWARDED_FOR")  
  end   if  
   
  Response.Write(GetMac(remoteaddr))  
  '由于读取某IP的网卡MAC地址  
  '本程序通过调用arp命令通过查询本机arp表读取特定IP的MAC地址  
  '使用本程序需注意以下事项:  
  '   本程序需要“WSCRIPT.SHELL”和“Scripting.FileSystemObject”两个组件,请确保您的服务器可以正常使用这两个组件  
  '   本程序需要调用cmd.exe程序,请确保IIS来宾帐号对程序有访问权限。  
  '   本程序需要临时文件保存结果,请确保IIS来宾帐号对临时目录有写权限。  
  '  
  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\"   '临时目录  
  szTempFile   =   TempPath   &   oFileSys.GetTempName()   '   获取临时文件名  
  Call   oScript.Run   ("cmd.exe   /c   ping   -n   2   "   &   IP,   0,   True)   '保证arp表中有此IP  
  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  
  %>  
     
     
  Top

13 楼adventure007(adventure)回复于 2005-04-03 14:46:23 得分 0

有用学习中Top

相关问题

  • 在.Net里面,有没有办法通过客户机MAC地址,对应的IP地址?高分求。
  • 客户机上不了邮件地址。
  • 如何检测客户机的IP地址。急!急!急!
  • 如何得到客户机的ip地址与计算机名
  • 如何修改客户机的DNS地址?
  • 如何在ASP中运行客户机上的文件?急!
  • 请问IdTCPServer中如何得到远程客户机的地址,或名称。
  • 怎样才能让客户机搜索到服务器的ip地址?
  • 如何在ASP页面中获取客户机的机器名(高手请进!)
  • 如何得到局域网上某一客户机拨号到另一远程服务器时的IP地址?

关键词

  • win32

得分解答快速导航

  • 帖主:syd41
  • liuxiaoyi666
  • yb2008

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo