本帖最后由 itzyx 于 2021-8-8 21:05 编辑
想写一个简单的小程序,首先需要先选择对应的以太网名称,然后更改其网段1~10,然后从1~255 看是否PING通,本来应该是 8网段才可以PING通 ,不知道为什么PING的结果显示2~5网段都可以PING通,各位大佬这是为什么?
然后单线程的PING IP就是这么慢嘛(1~10网段ping完要好几分钟),有没有提速的方法,我也搜索了相关标题,可惜P版的多线程PING 我现在还看不懂。下面是代码,希望大佬们能指点迷津,万分感谢!#include <WindowsConstants.au3>
Local $oClassSet, $oClass, $oLocator
Local $oService, $sMesStr
$CreateName = "Obtaining an IP address"
$Form1 = GUICreate($CreateName, 420, 120, -1, -1)
$Group1 = GUICtrlCreateGroup("", 8, 0, 400, 73)
$Label1 = GUICtrlCreateLabel("网络适配器:", 16, 20, 100, 17)
$Combo1 = GUICtrlCreateCombo("", 100, 16, 300, 100, 0003)
$button1 = GUICtrlCreateButton("Ping", 340, 80, 60, 30, $WS_BORDER)
GUISetState(@SW_SHOW)
$oLocator = ObjCreate("WbemScripting.SWbemLocator")
$oService = $oLocator.ConnectServer
$oClassSet = $oService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID IS NOT NULL")
For $oClass In $oClassSet
$sMesStr = $oClass.NetConnectionID
GUICtrlSetData($Combo1, $sMesStr)
Next
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $button1
$COM = GUICtrlRead($Combo1)
GUIDelete($Form1)
_PING()
ExitLoop
EndSwitch
WEnd
Func _PING()
Local $hTimer = TimerInit()
For $WAN = 1 To 10
Run(@ComSpec & ' /c netsh -c interface ip set address "' & $COM & '" static 192.168.' & $WAN & '.155 255.255.255.0 ', "", @SW_HIDE)
For $i = 1 To 255
$ip = Ping('192.168.' & $WAN & '.' & $i, 5)
If $ip <> 0 Then ExitLoop 2
Next
Next
Local $fDiff = TimerDiff($hTimer)
$fDiff = Round($fDiff / 1000, 2)
MsgBox(64, '提示', '共耗时:' & $fDiff & 's,IP:192.168.' & $WAN & '.' & $i)
EndFunc ;==>_PING
|