Good day! Tell me how to quickly ping a range of ip addresses with Resp output. Time, HostName, Mac? The form has a datagridview 2 text boxes and a button. Enter the range of ip addresses in the text fields, click on the button and the datagridview is filled.
there is the following code, which in a split second will include the number of active devices on the network. how is it possible to remake it for my task?
there is the following code, which in a split second will include the number of active devices on the network. how is it possible to remake it for my task?
code:
Private BaseIP As String = "192.168.1."
Private StartIP As Integer = 1
Private StopIP As Integer = 255
Private ip As String
Private timeout As Integer = 100
Private nFound As Integer = 0
Private Shared lockObj As New Object()
Private stopWatch As New Stopwatch()
Private ts As TimeSpan
Public Async Sub RunPingSweep_Async()
nFound = 0
Dim tasks = New List(Of Task)()
stopWatch.Start()
For i As Integer = StartIP To StopIP
ip = BaseIP & i.ToString()
Dim p As New System.Net.NetworkInformation.Ping()
Dim task = PingAndUpdateAsync(p, ip)
tasks.Add(task)
Next i
Await Task.WhenAll(tasks).ContinueWith(Sub(t)
stopWatch.Stop()
ts = stopWatch.Elapsed
MessageBox.Show(nFound.ToString() & " devices found! Elapsed time: " & ts.ToString(), "Asynchronous")
End Sub)
End Sub
Private Async Function PingAndUpdateAsync(ByVal ping As System.Net.NetworkInformation.Ping, ByVal ip As String) As Task
Dim reply = Await ping.SendPingAsync(ip, timeout)
If reply.Status = System.Net.NetworkInformation.IPStatus.Success Then
SyncLock lockObj
nFound += 1
End SyncLock
End If
End Function