风雨网络 发表于 2013-6-1 16:56:19

XP系统每次连接 接口列表都不一样怎么获取?

本帖最后由 风雨网络 于 2013-6-1 17:05 编辑

winxp win2003系统每次连接 接口列表都不一样怎么获取?图中0x20004 每次都不一样!



这个是论坛找的代码#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_UseUpx=n
#PRE_UseX64=n
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
Const $IPHLPAPI = DllOpen("iphlpapi.dll")
Const $tagMIB_IPFORWARDROW = "long Destination;long NetworkMask;long Policy;long NextHop;long IfIndex;long Type;long Proto;long Age;long NextHopAS;long Metric1;long Metric2;long Metric3;long Metric4;long Metric5"

Func _EnumIpForwordEntries()
      Local $iResult, $tBuffer, $tBinary, $pBinary, $tNumberofEntries, $aResult = []

      $iResult = DllCall($IPHLPAPI, "long", "GetIpForwardTable", "ptr", 0, "long*", 0, "bool", 1)
      If ($iResult < 4) Then Return SetError($iResult, 0, $aResult)

      $tBinary = DllStructCreate("ubyte Binary[" & $iResult & "]")
      $pBinary = DllStructGetPtr($tBinary)

      $iResult = DllCall($IPHLPAPI, "long", "GetIpForwardTable", "ptr", $pBinary, "long*", $iResult, "bool", 1)
      If ($iResult) Then Return SetError($iResult, 0, $aResult)

      $tNumberofEntries = DllStructCreate("long NumberofEntries", $pBinary)
      $aResult = DllStructGetData($tNumberofEntries, "NumberofEntries")
      Redim $aResult[$aResult + 1]

      For $i = 1 To $aResult
                $tBuffer = DllStructCreate($tagMIB_IPFORWARDROW, $pBinary + 4 + ($i - 1) * 56)

                For $j = 0 To 13
                        $aResult[$i][$j] = DllStructGetData($tBuffer, $j + 1)
                Next
                $aResult[$i] = _ConvertUlongToChars($aResult[$i])
                $aResult[$i] = _ConvertUlongToChars($aResult[$i])
                $aResult[$i] = _ConvertUlongToChars($aResult[$i])
      Next

      Return $aResult
EndFunc ;==>_EnumIpForwordEntries

Func _ConvertUlongToChars($iUlong)
      Local $iResult = DllCall("Ws2_32.dll", "str", "inet_ntoa", "ulong", $iUlong)
      Return $iResult
EndFunc ;==>_ConvertUlongToChars

Func _ConvertCharsToUlong($sChars)
      Local $iResult = DllCall("Ws2_32.dll", "long", "inet_addr", "str", $sChars)
      Return $iResult
EndFunc ;==>_ConvertCharsToUlong

Func _CreateIpForwardEntry($sDestination, $sNetworkMask, $sNextHop, $iIfIndex, $iType, $iMetric)
      Local $tBuffer, $iResult

      If $iIfIndex = -1 Then $iIfIndex = _GetBestInterface($sNextHop)

      $tBuffer = DllStructCreate($tagMIB_IPFORWARDROW)
      DllStructSetData($tBuffer, "Destination", _ConvertCharsToUlong($sDestination))
      DllStructSetData($tBuffer, "NetworkMask", _ConvertCharsToUlong($sNetworkMask))
      DllStructSetData($tBuffer, "NextHop", _ConvertCharsToUlong($sNextHop))
      DllStructSetData($tBuffer, "IfIndex", $iIfIndex)
      DllStructSetData($tBuffer ,"Type", $iType)
      DllStructSetData($tBuffer, "Proto", 3)
      DllStructSetData($tBuffer, "Policy", 0)
      DllStructSetData($tBuffer, "Age", 0)
      DllStructSetData($tBuffer, "NextHopAS", 0)
      DllStructSetData($tBuffer, "Metric1", $iMetric)
      DllStructSetData($tBuffer ,"Metric2", -1)
      DllStructSetData($tBuffer ,"Metric3", -1)
      DllStructSetData($tBuffer ,"Metric4", -1)
      DllStructSetData($tBuffer ,"Metric5", -1)

      $iResult = DllCall($IPHLPAPI, "long", "CreateIpForwardEntry", "ptr", DllStructGetPtr($tBuffer))
      Return SetError($iResult, 0, $iResult = 0)
EndFunc ;==>_CreateIpForwardEntry

Func _DeleteIpForwardEntry($sDestination, $sNetworkMask, $sNextHop, $iIfIndex, $iProto = 3)
      Local $iResult, $tBuffer

      If $iIfIndex = -1 Then $iIfIndex = _GetBestInterface($sNextHop)

      $tBuffer = DllStructCreate($tagMIB_IPFORWARDROW)
      DllStructSetData($tBuffer, "Destination", _ConvertCharsToUlong($sDestination))
      DllStructSetData($tBuffer, "NetworkMask", _ConvertCharsToUlong($sNetworkMask))
      DllStructSetData($tBuffer, "NextHop", _ConvertCharsToUlong($sNextHop))
      DllStructSetData($tBuffer, "IfIndex", $iIfIndex)
      DllStructSetData($tBuffer, "Proto", $iProto)

      $iResult = DllCall($IPHLPAPI, "long", "DeleteIpForwardEntry", "ptr", DllStructGetPtr($tBuffer))
      Return SetError($iResult, 0, $iResult = 0)
EndFunc ;==>_DeleteIpForwardEntry

Func _GetBestInterface($sAddress)
      Local $iResult

      $iResult = DllCall($IPHLPAPI, "long", "GetBestInterface", "long", _ConvertCharsToUlong($sAddress), "long*", 0)
      Return SetError($iResult, 0, $iResult)
EndFunc ;==>_GetBestInterface

If _CreateIpForwardEntry("221.239.208.1", "255.255.255.255", "192.168.0.215", -1, 3, 60) Then
      MsgBox(48, "OK", "Done")
Else
      MsgBox(48, "Error", "Failed with error " & @error)
EndIf

If _DeleteIpForwardEntry("221.239.208.1", "255.255.255.255", "192.168.0.215", -1) Then
      MsgBox(48, "OK", "Done")
Else
      MsgBox(48, "Error", "Failed with error " & @error)
EndIf

user3000 发表于 2013-6-1 18:40:32

回复 1# 风雨网络 $pid = Run(@ComSpec & ' /c route print', '', @SW_HIDE, 0x2)
ProcessWaitClose($pid)
$text = StringRegExpReplace(StdoutRead($pid), '(?ism).+^(0x\d+).+?WAN.+', '\1')
MsgBox(0, '', $text)
页: [1]
查看完整版本: XP系统每次连接 接口列表都不一样怎么获取?