找回密码
 加入
搜索
查看: 1304|回复: 4

[网络通信] 【已解决】请问如何提取相关信息出来?

[复制链接]
发表于 2021-3-4 19:57:30 | 显示全部楼层 |阅读模式
本帖最后由 229989799 于 2021-3-4 22:16 编辑

论坛找到的代码获取电脑网卡和描述,想提取相关信息出来,不知如何操作,请教一下大家,谢谢。

我想提取电脑上的2张环回网卡是以太网几,因为名字不固定,有些是以太网2和3,有些是以太网5和6。


因为有几千台机器需要把这2张环回适配器改名为太网11和以太网12。请大家帮忙看看。谢谢大家。

#include <array.au3>
$aArray = GetAdapterProperty()
_ArrayDisplay($aArray)

Func GetAdapterProperty()
        Local $objShare
        Local $objEveryColl
        $objShare = ObjCreate("HNetCfg.HNetShare.1")
        If Not IsObj($objShare) Then Return
        $objEveryColl = $objShare.EnumEveryConnection
        If Not IsObj($objEveryColl) Then Return
        Local $objNetConn, $objShareCfg, $objNCProps, $str
        Local $aProps[1][5] = [['网卡名称', 'Guid', '描述']]
        For $objNetConn In $objEveryColl
                $objShareCfg = $objShare.INetSharingConfigurationForINetConnection($objNetConn)
                If IsObj($objShareCfg) Then
                        $objNCProps = $objShare.NetConnectionProps($objNetConn)
                        If IsObj($objNCProps) Then
                                ReDim $aProps[UBound($aProps) + 1][5]
                                $aProps[UBound($aProps) - 1][0] = $objNCProps.Name
                                $aProps[UBound($aProps) - 1][1] = $objNCProps.Guid
                                $aProps[UBound($aProps) - 1][2] = $objNCProps.DeviceName
                                $aProps[UBound($aProps) - 1][3] = $objNCProps.Status
                                $aProps[UBound($aProps) - 1][4] = $objNCProps.MediaType
                        EndIf
                EndIf
        Next
        Return $aProps
EndFunc   ;==>GetAdapterProperty


本帖子中包含更多资源

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

×
发表于 2021-3-4 20:08:21 | 显示全部楼层
试试~ 名称存放在 $arr 中
#include <array.au3>

Local $arr
Local $aArray = GetAdapterProperty($arr)
_ArrayDisplay($aArray)
_ArrayDisplay($arr)

Func GetAdapterProperty(ByRef $arr)
        Local $objShare
        Local $objEveryColl
        $objShare = ObjCreate("HNetCfg.HNetShare.1")
        If Not IsObj($objShare) Then Return
        $objEveryColl = $objShare.EnumEveryConnection
        If Not IsObj($objEveryColl) Then Return
        Local $objNetConn, $objShareCfg, $objNCProps, $str
        Local $aProps[1][5] = [['网卡名称', 'Guid', '描述']]
        Local $sGet2 = ''
        For $objNetConn In $objEveryColl
                $objShareCfg = $objShare.INetSharingConfigurationForINetConnection($objNetConn)
                If IsObj($objShareCfg) Then
                        $objNCProps = $objShare.NetConnectionProps($objNetConn)
                        If IsObj($objNCProps) Then
                                ReDim $aProps[UBound($aProps) + 1][5]
                                $aProps[UBound($aProps) - 1][0] = $objNCProps.Name
                                $aProps[UBound($aProps) - 1][1] = $objNCProps.Guid
                                $aProps[UBound($aProps) - 1][2] = $objNCProps.DeviceName
                                If StringInStr($aProps[UBound($aProps) - 1][2], '环回适配器') Then
                                        $sGet2 &= $aProps[UBound($aProps) - 1][0] & @LF
                                EndIf
                                $aProps[UBound($aProps) - 1][3] = $objNCProps.Status
                                $aProps[UBound($aProps) - 1][4] = $objNCProps.MediaType
                        EndIf
                EndIf
        Next
        $arr = StringRegExp($sGet2, '\V+', 3)
        Return $aProps
EndFunc   ;==>GetAdapterProperty
 楼主| 发表于 2021-3-4 21:52:39 | 显示全部楼层
afan 发表于 2021-3-4 20:08
试试~ 名称存放在 $arr 中

多谢afan斑竹。如果转换成2行msgbox怎么处理呀,这个输出结果,如果转换成msgbox好像就是空白了
msgbox(0,'',''第1张网卡是:"&$arr1)
msgbox(0,'',''第2张网卡是:"&$arr2)
发表于 2021-3-4 21:55:29 | 显示全部楼层
229989799 发表于 2021-3-4 21:52
多谢afan斑竹。如果转换成2行msgbox怎么处理呀,这个输出结果,如果转换成msgbox好像就是空白了
msgbox( ...

msgbox(0,'',''第1张网卡是:"&$arr[0])
msgbox(0,'',''第2张网卡是:"&$arr[1])

点评

thanks for your help..i love you man  发表于 2021-3-4 22:06
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-19 15:05 , Processed in 0.084777 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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