#include <Array.au3>
Global $t = 0
Dim $iCount = 0
Dim $iIP = InputBox('On-Line Scaner!', 'Введите ip-адрес сервера', '93.81.248.130')
Dim $aPort[2] = [26000,29000]
Dim $aPort[3] = [21,80]
If @error <> 0 Then Exit
OnAutoItExitRegister("_Cleanup()")
AdlibRegister("_Timer", 300)
TCPStartup()
UDPStartup()
For $i = $aPort[0] To $aPort[1]
If _Status($iIP, $i) Then
$iCount += 1
$iMsg = MsgBox(262212, "On Line!", "Сервер найден!" &@LF & $iIP &":"& $i)
If $iMsg = 7 Then
ExitLoop
EndIf
EndIf
Next
MsgBox(262208, "Выполнено!", "Поиск серверов закончен!" & @LF & "Найден (" & $iCount & ") сервер.")
Func _Status($iIP, $iPort)
$_Socket = TCPConnect($iIP, $iPort)
$_Socket = UDPOpen($iIP, $iPort)
If @error <> 0 Then Exit
$_Status = UDPSend($_Socket, "0xFFFFFFFF6765746368616C6C656E6765")
If $_Status = 0 then
MsgBox(16, "Ошибка!", "Ошибка отправки сообщения: " & @error)
Exit
EndIf
Do
$iData = UDPRecv($_Socket, 100, 1)
If $iData <> "" Then
Return 1
EndIf
Until $t = 1
Return 0
EndFunc
Func _Timer()
$t = 1
Return $t
EndFunc
Func _Cleanup()
AdlibUnRegister("_Timer()")
UDPCloseSocket($_Socket)
TCPCloseSocket($_Socket)
TCPShutdown()
UDPShutdown()
EndFunc