求一段 查找本机网卡信息地址并显示的代码
如题原来在论坛上收藏过一段查看本机网卡信息的代码 非wmi的 可惜。。论坛坏了一次 都没有了
再次求一段 这样的代码
谢谢了
[ 本帖最后由 hynq2000 于 2008-6-2 04:04 编辑 ] 这个是读注册表的..谁给个别的方法.
Dim $key="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\"
$key2="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\"
$key3="\Parameters\Tcpip"
For $i= 1 to 10
$nic = RegEnumKey($key,$i)
$Description=RegRead ( $key & $nic, "Description" )
$ServiceName=RegRead ( $key & $nic, "ServiceName" )
If $Description <> "" And $ServiceName <> "" Then
$AdapterInfo = $key2 & $ServiceName & $key3
$DHCPStatus=RegRead ( $AdapterInfo, "EnableDHCP" )
If $DHCPStatus = "1" Then
$DHCPStatus = "DHCP Enabled"
Else
$DHCPStatus = "Static IP"
EndIf
$DHCPIPAddress=RegRead ( $AdapterInfo, "DhcpIPAddress" )
$DHCPSubnetMask=RegRead ( $AdapterInfo, "DhcpSubnetMask" )
$IPAddress=RegRead ( $AdapterInfo, "IPAddress" )
$SubnetMask=RegRead ( $AdapterInfo, "SubnetMask" )
$DHCPServer=RegRead ( $AdapterInfo, "DhcpServer" )
$out=$Description & @CRLF
$out&=$ServiceName & @CRLF
$out&="DHCP Status"&$DHCPStatus & @CRLF
$out&="DHCP IP"&$DHCPIPAddress & @CRLF
$out&="DHCP SubNet Mask"&$DHCPSubnetMask & @CRLF
$out&="Adapter IP"&$IPAddress & @CRLF
$out&="Adapter SubNet Mask"&$SubnetMask & @CRLF
$out&="DHCP Server"&$DHCPServer & @CRLF
MsgBox(0,"", $out)
EndIf
Next 谢谢 读注册表的方法 上次我都没有收集到啊。。。。
上次我看到的是一个dos的方法
用这个读注册表的不能读取网关信息
[ 本帖最后由 hynq2000 于 2008-5-16 14:02 编辑 ] 顶上去 期待大侠的出现 不知道下面一段是不是你要的:
Func Hgzzy_IP()
$ipfile = @TempDir & "\ip.txt"
If FileExists(@TempDir & "\ip.txt") Then FileDelete(@TempDir & "\ip.txt")
RunWait(@ComSpec & " /c netsh -c interface ip show address > " & $ipfile, "", @SW_HIDE)
$file = FileOpen($ipfile, 0)
;下面是获取IP地址
$i = 1
Do
$ipdq = FileReadLine($file, $i)
If @error = -1 Then ExitLoop
If StringInStr($ipdq, "IP 地址") = 0 Then
$i = $i + 1
$ip = ""
Else
$line = $i
$ip = StringTrimLeft(FileReadLine($file, $i), 38)
ExitLoop
EndIf
Until $i = 0
;下面是获取当前子网掩码
$i = $line
Do
$Maskdq = FileReadLine($file, $i)
If @error = -1 Then ExitLoop
If StringInStr($Maskdq, "子网掩码") = 0 Then
$i = $i + 1
$Mask = ""
Else
$line = $i
$Mask = StringTrimLeft(FileReadLine($file, $i), 36)
ExitLoop
EndIf
Until $i = 0
;下面是获取当前默认网关
$i = $line
Do
$Gatewaydq = FileReadLine($file, $i)
If @error = -1 Then ExitLoop
If StringInStr($Gatewaydq, "默认网关") = 0 Then
$i = $i + 1
$Gateway = ""
Else
$line1 = $i
$Gateway = StringTrimLeft(FileReadLine($file, $i), 30)
ExitLoop
EndIf
Until $i = 0
FileClose($file)
FileDelete($file)
EndFunc ;==>Hgzzy_IP
[ 本帖最后由 hgzzy 于 2008-5-17 12:03 编辑 ] netsh命令的也有了。。。期待更多的方法了..顶 谢谢 5楼的就是netsh命令
不过 netsh生成的文本信息 查找的方法 不是5楼用的,比5楼这个简单点 没有哪么多跳转
很适合新手的那个方法 给一个不相关的,通过IP地址获取MAC地址
$sIP = InputBox("MAC地址获取", "请输入IP地址", @IPAddress1, "", 150, 100, -1, -1)
$MAC = _GetMAC ($sIP)
If $MAC <> "00:00:00:00:00:00" Then
MsgBox (0, "MAC地址", '"' &$sIP& '" 的MAC地址是:'&$MAC)
Else
MsgBox (0, "MAC地址", '无法获取:"' &$sIP& '" 的MAC地址')
EndIf
Func _GetMAC ($sIP)
Local $MAC,$MACSize
Local $i,$s,$r,$iIP
$MAC = DllStructCreate("byte")
$MACSize = DllStructCreate("int")
DllStructSetData($MACSize,1,6)
$r = DllCall ("Ws2_32.dll", "int", "inet_addr", "str", $sIP)
$iIP = $r
$r = DllCall ("iphlpapi.dll", "int", "SendARP","int", $iIP,"int", 0,"ptr", DllStructGetPtr($MAC),"ptr", DllStructGetPtr($MACSize))
$s = ""
For $i = 0 To 5
If $i Then $s = $s & ":"
$s = $s & Hex(DllStructGetData($MAC,1,$i+1),2)
Next
Return $s
EndFunc 谢谢 学习了
页:
[1]