本帖最后由 txm888 于 2011-12-20 17:41 编辑 ;======================================================
;
; 函数名称: _NetworkAdapterInfo()
; 详细信息: 获得网卡信息
; 返回值说明:
; 以二维数组方式返回.例如 $info=_NetworkAdapterInfo()
; $info[0][0]=网卡数量
; $info[1][0]第一块网卡的标志1
; $info[2][0]第二块网卡的标志2
; $info[1][1]第一块网卡的网卡名称
; $info[2][1]第二块网卡的网卡名称
; $info[1][2]第一块网卡的默认网关
; $info[1][3]第一块网卡的DNS主机名称(本机名称)
; $info[1][4]第一块网卡的IP地址
; $info[1][5]第一块网卡的主DNS
; $info[1][6]第一块网卡的次DNS
; $info[1][7]第一块网卡的子网掩码
; $info[1][8]第一块网卡的MAC地址
; $info[1][9]第一块网卡的连接名称
; 注意,此UDF不会获取已经禁用的网卡。
; 如果有需要,请删除' WHERE IPEnabled != 0'和' WHERE NetConnectionStatus >0'
; 作者: thesnow(rundll32@126.com)
;
;======================================================
Func _NetworkAdapterInfo()
Local $colItems = ""
Local $objWMIService
Local $NetworkAdapterID = 0
Local $NetworkAdapterName = ""
Local $NetworkAdapterGateway = ""
Local $NetworkAdapterHostName = ""
Local $NetworkAdapterIPaddress = ""
Local $NetworkAdapterDNS1 = ""
Local $NetworkAdapterDNS2 = ""
Local $NetworkAdapterSubnet = ""
Local $NetworkAdapterMAC = ""
Local $NetworkAdapterNetConnectionID = ""
Local $NetworkAdapterInfo[10][10] ;最高10块网卡.
$NetworkAdapterInfo[0][0] = 0
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled != 0", "WQL", 0x10 + 0x20)
Local $colItem2 = $objWMIService.ExecQuery('SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionStatus >0', "WQL", 0x10 + 0x20)
If IsObj($colItems) Then
For $objItem In $colItems
$NetworkAdapterName = $objItem.Description
$NetworkAdapterGateway = $objItem.DefaultIPGateway(0)
$NetworkAdapterHostName = $objItem.DNSHostName
$NetworkAdapterIPaddress = $objItem.IPAddress(0)
$NetworkAdapterDNS1 = $objItem.DNSServerSearchOrder(0)
$NetworkAdapterDNS2 = $objItem.DNSServerSearchOrder(1)
$NetworkAdapterSubnet = $objItem.IPSubnet(0)
$NetworkAdapterMAC = $objItem.MACAddress
$NetworkAdapterID += 1
$NetworkAdapterInfo[0][0] = $NetworkAdapterID
$NetworkAdapterInfo[$NetworkAdapterID][0] = $NetworkAdapterID
$NetworkAdapterInfo[$NetworkAdapterID][1] = $NetworkAdapterName
$NetworkAdapterInfo[$NetworkAdapterID][2] = $NetworkAdapterGateway
$NetworkAdapterInfo[$NetworkAdapterID][3] = $NetworkAdapterHostName
$NetworkAdapterInfo[$NetworkAdapterID][4] = $NetworkAdapterIPaddress
$NetworkAdapterInfo[$NetworkAdapterID][5] = $NetworkAdapterDNS1
$NetworkAdapterInfo[$NetworkAdapterID][6] = $NetworkAdapterDNS2
$NetworkAdapterInfo[$NetworkAdapterID][7] = $NetworkAdapterSubnet
$NetworkAdapterInfo[$NetworkAdapterID][8] = $NetworkAdapterMAC
Next
Else
Return $NetworkAdapterInfo
EndIf
If IsObj($colItem2) Then
$NetworkAdapterID = 0
For $objItem2s In $colItem2
$NetworkAdapterNetConnectionID = $objItem2s.NetConnectionID
$NetworkAdapterID += 1
$NetworkAdapterInfo[$NetworkAdapterID][9] = $NetworkAdapterNetConnectionID
Next
Return $NetworkAdapterInfo
Else
Return $NetworkAdapterInfo
EndIf
EndFunc ;==>_NetworkAdapterInfo
问题在于这行$NetworkAdapterDNS2 = $objItem.DNSServerSearchOrder(1),比如在win2003系统下,若只设置第一DNS地址,不设置第二DNS地址,会导致请求对象失败,,,为了兼容更多系统能检查到第二DNS地址,同时又能避免此类问题再发生,请问各位大侠,有没有方法检测$objItem.DNSServerSearchOrder(1)这项是有效的?谢谢啦。。。 |