找回密码
 加入
搜索
查看: 3345|回复: 8

求一段 查找本机网卡信息地址并显示的代码

[复制链接]
发表于 2008-5-16 12:36:20 | 显示全部楼层 |阅读模式
如题
原来在论坛上收藏过一段查看本机网卡信息的代码 非wmi的 可惜。。论坛坏了一次 都没有了
再次求一段 这样的代码
谢谢了

[ 本帖最后由 hynq2000 于 2008-6-2 04:04 编辑 ]
发表于 2008-5-16 12:41:58 | 显示全部楼层
这个是读注册表的..谁给个别的方法.
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
 楼主| 发表于 2008-5-16 13:40:06 | 显示全部楼层
谢谢 读注册表的方法 上次我都没有收集到啊。。。。
上次我看到的是一个dos的方法

用这个读注册表的不能读取网关信息

[ 本帖最后由 hynq2000 于 2008-5-16 14:02 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2008-5-17 10:22:50 | 显示全部楼层
顶上去 期待大侠的出现
发表于 2008-5-17 11:59:00 | 显示全部楼层
不知道下面一段是不是你要的:

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 编辑 ]
发表于 2008-5-17 16:28:22 | 显示全部楼层
netsh命令的也有了。。。期待更多的方法了..顶
 楼主| 发表于 2008-5-17 16:37:13 | 显示全部楼层
谢谢 5楼的就是netsh命令
不过 netsh生成的文本信息 查找的方法 不是5楼用的,比5楼这个简单点 没有哪么多跳转
很适合新手的那个方法
发表于 2008-5-17 19:18:58 | 显示全部楼层
给一个不相关的,通过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[6]")
$MACSize = DllStructCreate("int")

DllStructSetData($MACSize,1,6)
$r = DllCall ("Ws2_32.dll", "int", "inet_addr", "str", $sIP)
$iIP = $r[0]
$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
 楼主| 发表于 2008-5-18 16:38:34 | 显示全部楼层
谢谢 学习了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-18 21:40 , Processed in 0.075787 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表