如何提取多网卡的IP地址,并分类
Windows IP Configuration
Ethernet adapter 本地连接 2:
Connection-specific DNS Suffix. :
IP Address. . . . . . . . . . . . : 10.185.122.122
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 10.185.122.1
Ethernet adapter 本地连接:
Connection-specific DNS Suffix. :
IP Address. . . . . . . . . . . . : 192.168.1.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.3
得到这样的结果
[本地连接 2]
IP=10.185.122.122
掩码255.255.255.0
网关=10.185.122.1
[本地连接]
IP=192.168.1.1
掩码=255.255.255.0
网关=192.168.1.3 自己封装一个
#include <Array.au3>
$array = getip()
_ArrayDisplay($array)
Func getip()
RunWait(@ComSpec & " /c " & "ipconfig /all>" & @TempDir & "\ip.txt", "", @SW_HIDE)
Sleep(2000)
Local $fp = FileOpen(@TempDir & "\ip.txt")
Local $buf = FileRead($fp)
Local $buf2 = ""
FileClose($fp)
Local $a = ;
Local $i = StringInStr($buf, "IP Address")
While $i <> 0
$i = StringInStr($buf, "adapter")
$buf = StringMid($buf, $i)
$i = StringInStr($buf, ":")
$buf2 = StringLeft($buf, $i-1)
$buf2 = StringMid($buf2, StringLen("adapter")+1)
_ArrayAdd($a, $buf2)
$a += 1
$i = StringInStr($buf, "IP Address")
$buf = StringMid($buf, $i)
$i = StringInStr($buf, ":")
$buf = StringMid($buf, $i + 1)
$i = StringInStr($buf, "Subnet Mask")
$buf2 = StringLeft($buf, $i - 1)
_ArrayAdd($a, get($buf2))
$a += 1
$i = StringInStr($buf, "Subnet Mask")
$buf = StringMid($buf, $i)
$i = StringInStr($buf, ":")
$buf = StringMid($buf, $i + 1)
$i = StringInStr($buf, "Default Gateway")
$buf2 = StringLeft($buf, $i - 1)
_ArrayAdd($a, get($buf2))
$a += 1
$i = StringInStr($buf, "Default Gateway")
$buf = StringMid($buf, $i)
$i = StringInStr($buf, ":")
$buf = StringMid($buf, $i + 1)
$i = StringInStr($buf, @CR)
$buf2 = StringLeft($buf, $i - 1)
_ArrayAdd($a, get($buf2))
$a += 1
$i = StringInStr($buf, "IP Address")
WEnd
Return $a
EndFunc
Func get(ByRef $str)
If $str = "" Then Return ""
Local $a = StringToASCIIArray($str)
Local $i
For $i = UBound($a) - 1 To 0 Step -1
If ($a[$i] >= Asc('0') And $a[$i] <= Asc('9')) Or ($a[$i] = Asc('.')) Then
;
Else
_ArrayDelete($a, $i)
EndIf
Next
Return StringFromASCIIArray($a)
EndFunc
进一步测试 借助安装的vm虚拟机 把网络连接里 两个vm 的 开起来
呵呵,不错,不错,学习了,谢谢 学习,学习了,谢谢{:face (361):} 学习学习。学习学习。 学习+收藏! 学习,谢谢源码分享
; 可以得到IP和网卡CLSID
Global Const $REG_Network_INTERFACE = 'HKLM\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces'
; 得到网卡显示名称
Global Const $REG_Network_Connection = 'HKLM\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}'
从这两个注册表项可得到你需要的东西,自由发挥即可 代码学习了. 这个我之前貌似研究过,回头我帮你找找! 再来个 读注册表的
#include <Array.au3>
$a = MuliNetCard()
_ArrayDisplay($a)
Func MuliNetCard()
Local $key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network"
Local $key1
Local $array =
Local $sub
Local $sub2
Local $val
Local $name
Local $i
Local $j
Local $keytcp = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"
Local $ip
Local $mask
Local $gateway
$i = 1
While True
$sub = RegEnumKey($key, $i)
If @error <> 0 Then ExitLoop
$i += 1
$val = RegRead($key & "\" & $sub, "Class")
If $val = "net" Then ExitLoop
WEnd
$key1 = $key & "\" & $sub
$i = 1
While True
$sub = RegEnumKey($key1, $i)
If @error <> 0 Then ExitLoop
$i += 1
$j = 1
$sub2 = ""
While True
$sub2 = RegEnumKey($key1 & "\" & $sub, $j)
If @error <> 0 Then ExitLoop
$j += 1
If $sub2 = "Connection" Then ExitLoop
WEnd
If $sub2 = "Connection" Then
$name = RegRead($key1 & "\" & $sub & "\Connection", "Name")
_ArrayAdd($array, $sub)
_ArrayAdd($array, $name)
_ArrayAdd($array, "ip")
_ArrayAdd($array, "mask")
_ArrayAdd($array, "gateway")
$array += 5
EndIf
WEnd
For $i = 1 To $array Step 5
$ip = RegRead($keytcp & "\" & $array[$i], "IPAddress")
$mask = RegRead($keytcp & "\" & $array[$i], "IPAutoconfigurationMask")
$gateway = RegRead($keytcp & "\" & $array[$i], "DefaultGateway")
$array[$i + 2] = $ip
$array[$i + 3] = $mask
$array[$i + 4] = $gateway
Next
Return $array
EndFunc
不错,谢谢楼主分享 win7下无效,不过我用的另外一种笨方式 我怎么显示是0
页:
[1]
2