Страница: 1 |
|
Вопрос: Поиск серверов Winsock. (vb6)
|
Добавлено: 09.04.10 21:45
|
|
Автор вопроса: oi
|
Как организовать поиск серверов Winsockа в vb6?
Типо порт 1234 и сканировать все IP, и в список добавлять те, которые ответили.
Ответить
|
Номер ответа: 5 Автор ответа: oi
Вопросов: 5 Ответов: 10
|
Профиль | | #5
|
Добавлено: 10.04.10 12:45
|
дайте ссылку плиз
Ответить
|
Номер ответа: 6 Автор ответа: Smith
ICQ: adamis@list.ru
Вопросов: 153 Ответов: 3632
|
Профиль | | #6
|
Добавлено: 11.04.10 14:16
|
Вариант 1 говорят роботает отлично- Function PingSilent(strComputer)
-
- Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
- ExecQuery("select * from Win32_PingStatus where address = '"_
- & strComputer & "'")
-
- For Each objStatus in objPing
- If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
- PingSilent = 0
- Else
-
- PingSilent = 1
- End If
- Next
-
- End Function
Вариант 2- Option Explicit
-
- Const SOCKET_ERROR = 0
- Const MAX_IP = 10
-
- Private Type WSAdata
- wVersion As Integer
- wHighVersion As Integer
- szDescription(0 To 255) As Byte
- szSystemStatus(0 To 128) As Byte
- iMaxSockets As Integer
- iMaxUdpDg As Integer
- lpVendorInfo As Long
- End Type
-
- Private Type Hostent
- h_name As Long
- h_aliases As Long
- h_addrtype As Integer
- h_length As Integer
- h_addr_list As Long
- End Type
-
- Private Type IP_OPTION_INFORMATION
- TTL As Byte
- Tos As Byte
- Flags As Byte
- OptionsSize As Long
- OptionsData As String * 128
- End Type
-
- Private Type IP_ECHO_REPLY
- Address(0 To 3) As Byte
- Status As Long
- RoundTripTime As Long
- DataSize As Integer
- Reserved As Integer
- data As Long
- Options As IP_OPTION_INFORMATION
- End Type
-
- Private Declare Function GetHostByName Lib "wsock32.dll" Alias "gethostbyname" (ByVal HostName As String) As Long
- Private Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVersionRequired&, lpWSAdata As WSAdata) As Long
- Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
- Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
- Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long
- Private Declare Function IcmpCloseHandle Lib "icmp.dll" (ByVal HANDLE As Long) As Boolean
- Private Declare Function IcmpSendEcho Lib "ICMP" (ByVal IcmpHandle As Long, ByVal DestAddress As Long, ByVal RequestData As String, ByVal RequestSize As Integer, RequestOptns As IP_OPTION_INFORMATION, ReplyBuffer As IP_ECHO_REPLY, ByVal ReplySize As Long, ByVal TimeOut As Long) As Boolean
-
- Public Function Ping(sAddr As String, Optional Timeout As Integer = 2000) As Integer
- Dim hFile As Long, lpWSAdata As WSAdata
- Dim hHostent As Hostent, AddrList As Long
- Dim Address As Long, rIP As String
- Dim OptInfo As IP_OPTION_INFORMATION
- Dim EchoReply As IP_ECHO_REPLY
-
- Call WSAStartup(&H101, lpWSAdata)
-
- If GetHostByName(sAddr + String(64 - Len(sAddr), 0)) <> SOCKET_ERROR Then
- CopyMemory hHostent.h_name, ByVal GetHostByName(sAddr + String(64 - Len(sAddr), 0)), Len(hHostent)
- CopyMemory AddrList, ByVal hHostent.h_addr_list, 4
- CopyMemory Address, ByVal AddrList, 4
- End If
-
- hFile = IcmpCreateFile()
-
- If hFile = 0 Then
- Ping = -2
- Exit Function
- End If
-
- OptInfo.TTL = 255
-
- If IcmpSendEcho(hFile, Address, String(32, "A"), 32, OptInfo, EchoReply, Len(EchoReply) + 8, Timeout) Then
- rIP = CStr(EchoReply.Address(0)) + "." + CStr(EchoReply.Address(1)) + "." + CStr(EchoReply.Address(2)) + "." + CStr(EchoReply.Address(3))
- Else
- Ping = -1
- End If
-
- If EchoReply.Status = 0 Then
- Ping = EchoReply.RoundTripTime
- Else
- Ping = -3
- End If
-
- IcmpCloseHandle hFile
- WSACleanup
-
- End Function
Я не проверял, смотри сам
Ответить
|
Страница: 1 |
Поиск по форуму