局域网中根据网卡物理地址命名计算机使用者
当获取网卡物理地址后,直接报告为使用者的名字。就是命名。运行以下代码,结果为:网卡物理地址为:00-10-D4-Y6-21。而我想让它报告为:网卡物理地址为:李三。就是把“00-10-D4-Y6-21”报成“李三”,而这些就要定义过。因为,是根据物理地址来判断,那么。就得在这代码中加入如:“00-10-D4-Y6-21”就等于“李三”,“00-10-D4-Y6-JH”等于“张四”,………………。只要一运行这程序,程序自动读取本电脑网卡物理地址,一再在定义中找到相应的网卡号,再直接显示出“李三”呀“张四”。这怎么实现,请高手帮忙。谢谢。用户机器名-----显示IP地址\
根据IP地址-----来确定MAC地址Option Explicit
Dim objSWbemServices As SWbemServices
Dim objSWbemObjectSet As SWbemObjectSet
Dim objSWbemObject As SWbemObject
Private Type NetCard
Name As String
IPAdress As String
IpSubNets As String
IpGateWay As String
DnsString0 As String
DnsString1 As String
MacAdress As String
End Type
Dim MtNetCard() As NetCard
Private Sub Command1_Click()
Dim i As Long
For i = LBound(MtNetCard) To UBound(MtNetCard) - 1
Text1 = Text1 & "网卡物理地址为: " & MtNetCard(i).DnsString1 & vbNewLine
Next
Erase MtNetCard
End SubPrivate Sub Form_Load()
ReDim MtNetCard(0) As NetCard
Set objSWbemServices = GetObject("winmgmts:")
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each objSWbemObject In objSWbemObjectSet
On Error Resume Next
MtNetCard(UBound(MtNetCard)).Name = objSWbemObject.Description '添加本机上已经安装了TCP/IP协议的网卡
MtNetCard(UBound(MtNetCard)).IPAdress = objSWbemObject.IPAddress(0)
MtNetCard(UBound(MtNetCard)).IpSubNets = objSWbemObject.IPSubnet(0)
MtNetCard(UBound(MtNetCard)).IpGateWay = objSWbemObject.DefaultIPGateway(0)
MtNetCard(UBound(MtNetCard)).DnsString0 = objSWbemObject.DNSServerSearchOrder(0)
MtNetCard(UBound(MtNetCard)).DnsString1 = objSWbemObject.DNSServerSearchOrder(1)
MtNetCard(UBound(MtNetCard)).DnsString1 = objSWbemObject.MacAddress(0)
ReDim Preserve MtNetCard(UBound(MtNetCard) + 1) As NetCard
Next
End Sub
当获取网卡物理地址后,直接报告为使用者的名字。就是命名。运行以下代码,结果为:网卡物理地址为:00-10-D4-Y6-21。而我想让它报告为:网卡物理地址为:李三。就是把“00-10-D4-Y6-21”报成“李三”,而这些就要定义过。因为,是根据物理地址来判断,那么。就得在这代码中加入如:“00-10-D4-Y6-21”就等于“李三”,“00-10-D4-Y6-JH”等于“张四”,………………。只要一运行这程序,程序自动读取本电脑网卡物理地址,一再在定义中找到相应的网卡号,再直接显示出“李三”呀“张四”。这怎么实现,请高手帮忙。谢谢。用户机器名-----显示IP地址\
根据IP地址-----来确定MAC地址Option Explicit
Dim objSWbemServices As SWbemServices
Dim objSWbemObjectSet As SWbemObjectSet
Dim objSWbemObject As SWbemObject
Private Type NetCard
Name As String
IPAdress As String
IpSubNets As String
IpGateWay As String
DnsString0 As String
DnsString1 As String
MacAdress As String
End Type
Dim MtNetCard() As NetCard
Private Sub Command1_Click()
Dim i As Long
For i = LBound(MtNetCard) To UBound(MtNetCard) - 1
Text1 = Text1 & "网卡物理地址为: " & MtNetCard(i).DnsString1 & vbNewLine
Next
Erase MtNetCard
End SubPrivate Sub Form_Load()
ReDim MtNetCard(0) As NetCard
Set objSWbemServices = GetObject("winmgmts:")
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each objSWbemObject In objSWbemObjectSet
On Error Resume Next
MtNetCard(UBound(MtNetCard)).Name = objSWbemObject.Description '添加本机上已经安装了TCP/IP协议的网卡
MtNetCard(UBound(MtNetCard)).IPAdress = objSWbemObject.IPAddress(0)
MtNetCard(UBound(MtNetCard)).IpSubNets = objSWbemObject.IPSubnet(0)
MtNetCard(UBound(MtNetCard)).IpGateWay = objSWbemObject.DefaultIPGateway(0)
MtNetCard(UBound(MtNetCard)).DnsString0 = objSWbemObject.DNSServerSearchOrder(0)
MtNetCard(UBound(MtNetCard)).DnsString1 = objSWbemObject.DNSServerSearchOrder(1)
MtNetCard(UBound(MtNetCard)).DnsString1 = objSWbemObject.MacAddress(0)
ReDim Preserve MtNetCard(UBound(MtNetCard) + 1) As NetCard
Next
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货