|
关于多网络卡检测的高级应用!!~~
现在本人在论坛朋友的帮助下。可以正确检测到网卡的数量及名字 但问题是无法正确获取 各网卡的IP地址.MASK等
和为多网卡分别进行IP修改....不知以上问题。如何处理。。 现特发源代码以供大家参考及帮助。。
以下为完整源代码:
Opt("TrayMenuMode", 1)
Opt('MustDeclareVars', 1)
#include <Array.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#Region ### START Koda GUI section ### Form=c:\documents and settings\cface\桌面\222.kxf
;Opt("TrayIconHide", 1)
Dim $ret = "", $bt11, $nMsg, $input, $s, $s1, $ttt = 22, $i = 0, $wk1, $card[20], $setcard = '',$ip1,$ip1mask,$ip2,$ip2mask
getipinfo()
Local $msg
GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered
GUICtrlCreateLabel("请选择网克使用网卡:", 10, 30)
For $i = 1 To $card[0]
$setcard &= $card[$i] & '|'
Next
$input = GUICtrlCreateCombo('请选择一块网卡', 10, 50, 380, 20,0x0003) ; create first item
if $setcard="" then
GUICtrlSetData($input, "本机未检测到任何网络设备") ; add other item snd set a new default
Else
GUICtrlSetData($input, $setcard) ; add other item snd set a new default
EndIf
$bt11 = GUICtrlCreateButton("测试", 100, 160, 50, 30)
MsgBox(64,"网卡1IP检测",$ip1)
MsgBox(64,"网卡1MASK检测",$ip1mask)
MsgBox(64,"网卡2IP检测",$ip2)
MsgBox(64,"网卡2MASK检测",$ip2mask)
GUISetState()
$s = GUICtrlRead($input)
$nMsg=""
While 1
$nMsg = GUIGetMsg()
Select
Case $nMsg = $GUI_EVENT_CLOSE
Exit
Case $nMsg = $bt11
$s1 = GUICtrlRead($input)
MsgBox(64,"网卡检测:",$s1)
EndSelect
WEnd
Func getipinfo() ;获取本机网卡全部信息
Local $wbemFlagReturnImmediately, $wbemFlagForwardOnly, $deip, $demask, $dedns, $dedns2, $degete, $dename
Local $network, $strComputer, $objWMIService, $colItems, $Output, $strIPAddress, $strDNSServerSearchOrder, $strIPSubnet
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output = ""
$Output = $Output & "计 算 机:" & $strComputer & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled != 0", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
Local $check2 = '', $check1 = '', $counter = 0
If IsObj($colItems) Then
For $objItem In $colItems
$Output = $Output & "网 卡: " & $objItem.Description & @CRLF
;$strDefaultIPGateway = $objItem.DefaultIPGateway(0)
$Output = $Output & "默认网关: " & $objItem.DefaultIPGateway(0) & @CRLF
$Output = $Output & "计算机名: " & $objItem.DNSHostName & @CRLF
$strIPAddress = $objItem.IPAddress(0)
$Output = $Output & "I P地址: " & $strIPAddress & @CRLF
$strDNSServerSearchOrder = $objItem.DNSServerSearchOrder(0)
$Output = $Output & "默认 DNS: " & $strDNSServerSearchOrder & @CRLF
$strDNSServerSearchOrder = $objItem.DNSServerSearchOrder(1)
$Output = $Output & "备用 DNS: " & $strDNSServerSearchOrder & @CRLF
$strIPSubnet = $objItem.IPSubnet(0)
$Output = $Output & "子网掩码: " & $strIPSubnet & @CRLF
$Output = $Output & "M AC地址: " & $objItem.MACAddress & @CRLF
if Msgbox(1,"WMI获取的信息:",$Output) = 2 then ExitLoop
$Output = ""
$check1 = $objItem.MACAddress
If $check1 = $check2 Then
If $check1 = '' Then Return MsgBox(64, '', '无网上卡')
ExitLoop
EndIf
$check2 = $check1
$counter += 1
$card[0] += 1
$dedns = $objItem.DNSServerSearchOrder(0)
$dedns2 = $objItem.DNSServerSearchOrder(1)
$degete = $objItem.DefaultIPGateway(0)
$dename = $objItem.DNSHostName
$card[$counter] = $objItem.Description & $counter
Next
For $i = 1 To $counter
$ip1=$strIPAddress
$ip1mask=$strIPSubnet
Next
EndIf
if $i=3 Then
$ip2=$strIPAddress
$ip2mask=$strIPSubnet
Else
EndIf
EndFunc ;==>getipinfo
现在本人在论坛朋友的帮助下。可以正确检测到网卡的数量及名字 但问题是无法正确获取 各网卡的IP地址.MASK等
和为多网卡分别进行IP修改....不知以上问题。如何处理。。 现特发源代码以供大家参考及帮助。。
[ 本帖最后由 zhenglei 于 2008-10-23 12:40 编辑 ] |
|