Link to home
Start Free TrialLog in
Avatar of plq
plqFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Using .NET ping to find devices on a network

I am finding that the PING function that ships in VB.NET seems to not always work on corporate networks, so I want to know what I can do to improve the probability of finding a host at an address.

The program allows the user to enter a list of addresses, and then it pings each address within that range and returns a table of devices

What I'm finding on large corporate networks is

1. The ping doesnt always find a device at an address even when a device is there
2. If I run it multi threaded, the probability of finding a device seems to reduce further
3. I have set default timeout to 100, and TTL=255, but so far I am only pinging each box once, whereas DOS ping obviosuly pings 4 times

Even with timeout upped to 5000, the problem exists.

I dont get many shots are large networks, so really I want to get it right next time..

My questions are:

(a) Would increasing the number of attempts from 1 to 4 or even more help ?
(b) Does it matter what size of data you send. I don't actually tell ping what data to send, so I suppose there must be a default byte array that it sends
(c) What other parameters can I set to get the absolute maximum probability of a ping response
(d) Multi threaded is definitely needed due to the time for each ping on a slow network, so any discussion on parameters related to multithreading would be appreciated




(c)
Public Function Ping(ByRef sAddress As String, ByRef sDataToSend As String, _
            ByVal lTimeOut As Integer, ByVal lTtl As Integer, _
            ByRef lResult As System.Net.NetworkInformation.IPStatus) As Integer
 
        Dim sn As New System.Net.NetworkInformation.Ping
        Dim re As System.Net.NetworkInformation.PingReply
        Dim op As New System.Net.NetworkInformation.PingOptions
 
        If sAddress = "" Then
            Return 0
        End If
 
        op.Ttl = lTtl
 
        Try
            re = sn.Send(sAddress, lTimeOut)
        Catch ex As System.Net.NetworkInformation.PingException
            Return 0
        Catch ex As System.Exception
            Return 0
        End Try
 
 
        lResult = re.Status
        If lResult = System.Net.NetworkInformation.IPStatus.Success Then
            Return 1
        Else
            Return 0
        End If
 
    End Function

Open in new window

Avatar of oleggold
oleggold
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of Joel Coehoorn
Joel Coehoorn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of plq

ASKER

Yes the product supports many protocols incl snmp but ping is the one most customers choose since most devices support it, dont block it, whereas snmp is often turned off these days.

thanks for the feedback. Any further comments would be appreciated..