Чтобы закрыть тему... готовый модуль поиска камер в сети (VB.NET):
Код:
Module DLINK
Dim c_request_2() As Byte = {&HFD, &HFD, &H1, &H0, &HA1, 0, &HFF, &HFF, &HFF, &HFF, &HFF, &HFF, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}
Public c_results As New Collection
Public Class CamInfo
Public Vendor As String
Public Model As String
Public Firmware As String
Public NetworkName As String
Public Hex As String
Public MAC As String
Public IP As String
End Class
Private Function ToHex(ByVal bytes() As Byte) As String
Dim res As String = ""
For Each b As Byte In bytes
res &= If(res = "", "", " ") & Hex(b).PadLeft(2, "0")
Next
Return res
End Function
Private Sub ReciveThread(ByVal s As Object)
Dim u As Net.Sockets.UdpClient = s
While True
Dim buff(512) As Byte
Dim cnt As Integer
Try
cnt = u.Client.Receive(buff, 512, Net.Sockets.SocketFlags.None)
Catch ex As Exception
Exit While
End Try
ReDim Preserve buff(cnt - 1)
Dim src As String = System.Text.Encoding.Default.GetString(buff)
If cnt > c_request_2.Length Then
Dim c As New CamInfo
With c
.Vendor = Mid(src, 23, 16).Trim(Chr(0))
.Model = Mid(src, 87, 32).Trim(Chr(0))
.Firmware = Mid(src, 183, 8).Trim(Chr(0))
.NetworkName = Mid(src, 227, 32).Trim(Chr(0))
.Hex = ToHex(buff)
Dim mac(5) As Byte
Array.Copy(buff, 6, mac, 0, 6)
.MAC = ToHex(mac)
.IP = String.Format("{0}.{1}.{2}.{3}", CInt("&H" & Hex(buff(12))), CInt("&H" & Hex(buff(13))), CInt("&H" & Hex(buff(14))), CInt("&H" & Hex(buff(15))))
End With
c_results.Add(c)
End If
End While
End Sub
Public Function SearchCams(Optional ByVal Timeout As Integer = 1000) As Collection
c_results.Clear()
Dim udp As New Net.Sockets.UdpClient()
udp.Client.Bind(New Net.IPEndPoint(Net.IPAddress.Any, 62976))
Dim th As New Threading.Thread(AddressOf ReciveThread)
th.Start(udp)
udp.Send(c_request_2, c_request_2.Length, New Net.IPEndPoint(Net.IPAddress.Broadcast, 62976))
Threading.Thread.Sleep(Timeout)
udp.Close()
Return c_results
End Function
End Module
Пример использования:
Код:
ListView1.Items.Clear()
For Each c As CamInfo In SearchCams(1000)
With ListView1.Items.Add(c.Vendor)
.SubItems.Add(c.Model)
.SubItems.Add(c.Firmware)
.SubItems.Add(c.NetworkName)
.SubItems.Add(c.MAC)
.SubItems.Add(c.IP)
.SubItems.Add(c.Hex)
End With
Next