Results 1 to 6 of 6

Thread: [RESOLVED] Problem with My.Computer.Network.Ping

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Resolved [RESOLVED] Problem with My.Computer.Network.Ping

    I'm trying do do something that on the face of it should be pretty easy,basically I'm trying to ping a range of IP addresses and list the ones that respond in a listbox.
    The code below actually does ping the ip addresses and lists the ones that respond in the listbox but there are a few problems.

    1. the IP addresses that respond are only listed when the whole process is complete, what I want it to do is add the address as it responds so a list is 'seen' to be created.

    2.The label that should show the current address being pinged doesn't, it just shows the final address, again this happens when the whole process is complete.

    3. Finally and most seriously the process takes and absolute age to complete, even if i set the time out in My.Computer.Network.Ping to 10ms, I've really no idea why its taking so long, according to the info in VS2005 express help it seems that only one atempt is made to contact the address so the whole process should complete in around 3 seconds but it's more like 2 mins

    VB Code:
    1. Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
    2.         Dim i As Integer
    3.         Dim strIP As String
    4.         For i = 1 To 254
    5.             strIP = txtSubNet.Text & "." & i
    6.             'display the current IP address being pinged
    7.             lblCurrentPing.Text = strIP
    8.             If My.Computer.Network.Ping(strIP) Then
    9.                 'if the IP address responded add to the listbox
    10.                 lstIPaddress.Items.Add(strIP)
    11.             End If
    12.         Next
    13.     End Sub

    any help greatly appreciated

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Problem with My.Computer.Network.Ping

    A couple of refresh commands should do the trick for questions 1 and 2.. one after your label, and one after you add an item to the listbox...
    VB Code:
    1. Dim i As Integer
    2.         Dim strIP As String
    3.         For i = 1 To 254
    4.             strIP = txtSubNet.Text & "." & i
    5.             'display the current IP address being pinged
    6.             lblCurrentPing.Text = strIP
    7.             [U]lblCurrentPing.Refresh()[/U]
    8.             If My.Computer.Network.Ping(strIP) Then
    9.                 'if the IP address responded add to the listbox
    10.                 lstIPaddress.Items.Add(strIP)
    11.                 [U]lstIPAddress.Refresh()[/U]
    12.             End If
    13.         Next
    Not sure about the speed question, though. there is a parameter for the .Ping to add a threshold integer (representing the milliseconds) for timeout, it made it faster, but like you said, it still isn't as quick.... but does .Ping do multiple tries?? Like commandline ping? 4 tries? Could explain it taking a little longer...

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Problem with My.Computer.Network.Ping

    I have just finished a very similar application and I used this article as a starting point.

    Hope it helps.

    Gary

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: Problem with My.Computer.Network.Ping

    Thanks for the info on the refresh, something new I've learned

    As far as I understand .Ping tries once to access the address, if I setup the loop so it pings 2 addresses that I know will not respond and set the timeout to 1000 then it takes 2 seconds to complete which is what I'd expect.

    It seems to be cumlative in as much as the more none responsive addresses it comes across the greater time it takes on each one so the net result is a long delay in completeing the task.

    As an example i set the loop to ping 5 none responsive addresses and it took 28 seconds to complete even with the timeout threshold set to 50ms, thats 5.6 seconds a ping !

    Maybe it's bugged ?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: Problem with My.Computer.Network.Ping

    Quote Originally Posted by gep13
    I have just finished a very similar application and I used this article as a starting point.

    Hope it helps.

    Gary
    Thanks Gary that looks perfect

    Still confused as to why My.Computer.Network.Ping gives me a headache

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Problem with My.Computer.Network.Ping

    Hello

    From my experience if you are looping the pings one after the other then it will appear to take a long time, especially if some of the pings are non-responsive. The article I pointed you at gets round this by creating each ping as a seperate thread. The author suggests that the program works reliably with up to and including 200 seperate IP addresses.

    I extended my program to include a timer for each IP that I am pinging, with this timer recording how long an IP address has been "UP" for or "DOWN" for, with an additional "WARNING" state, i.e. if there are three dropped packets it moves to the warning state and then after six say it would move to "DOWN". A little bit of overkill maybe, but we are trying to monitor connections to our VPN, so a record of exactly how long a connection has been up or down for is very useful.

    If you need any more help, I will try as best as I can.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width