|
-
Dec 21st, 2005, 06:15 PM
#1
Thread Starter
Hyperactive Member
[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:
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
Dim i As Integer
Dim strIP As String
For i = 1 To 254
strIP = txtSubNet.Text & "." & i
'display the current IP address being pinged
lblCurrentPing.Text = strIP
If My.Computer.Network.Ping(strIP) Then
'if the IP address responded add to the listbox
lstIPaddress.Items.Add(strIP)
End If
Next
End Sub
any help greatly appreciated
-
Dec 21st, 2005, 06:34 PM
#2
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:
Dim i As Integer
Dim strIP As String
For i = 1 To 254
strIP = txtSubNet.Text & "." & i
'display the current IP address being pinged
lblCurrentPing.Text = strIP
[U]lblCurrentPing.Refresh()[/U]
If My.Computer.Network.Ping(strIP) Then
'if the IP address responded add to the listbox
lstIPaddress.Items.Add(strIP)
[U]lstIPAddress.Refresh()[/U]
End If
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...
-
Dec 22nd, 2005, 03:51 AM
#3
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
-
Dec 22nd, 2005, 03:51 AM
#4
Thread Starter
Hyperactive Member
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 ?
-
Dec 22nd, 2005, 03:56 AM
#5
Thread Starter
Hyperactive Member
Re: Problem with My.Computer.Network.Ping
 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
-
Dec 22nd, 2005, 04:04 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|