自己封装一个
#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[1] = [0];
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[0] += 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[0] += 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[0] += 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[0] += 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
|