We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,993 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Program like pinger

hi everyone! i was wondering if anyone could hed me in the right direction 2 programming a program like pinger (preferably vb.net). i have visual studio .net 10 so can someone help me? thx!

2
Contributors
5
Replies
8 Hours
Discussion Span
6 Months Ago
Last Updated
7
Views
Programmer629
Light Poster
35 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

To start with you can ping another node by

My.Computer.Network.Ping(txtWeb.Text)

where txtWeb.Text is an IP address or DNS address

If you just want to do the occasional ping then that should suffice. If you want to use it to repeatedly monitor another address while you do other things then you should use a BackgroundWorker. This could run in another thread and update a status variable available to the main thread. It's not that hard to do and if you want to go that route I can show you how.

Reverend Jim
Carpe per diem
Moderator
3,600 posts since Aug 2010
Reputation Points: 561
Solved Threads: 447
Skill Endorsements: 32

thx! i do wanna go that route.

Programmer629
Light Poster
35 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Try the following (I zipped and attached the project folder). Feel free to ask any follow-up questions. Start the program. The starting address is www.google.com but feel free to replace this with another name or IP address. You can modify the address while the thread is running. Try various IP addresses to see the status change.

Public Class Form1

    'Background threads cannot write to controls in other threads. In order to update
    'the status label you have to access it through a delegate. You'll see how this
    'works in the UpdateStatus Sub.

    Private Delegate Sub UpdateStatusDelegate(text As String)

    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        'If the background thread is active, kill it. We already have the code in
        'the button click handler so let's just use that.

        If btnStart.Text = "Stop" Then
            btnStart.PerformClick()
        End If

    End Sub

    Private Sub btnStart_Click(sender As System.Object, e As System.EventArgs) Handles btnStart.Click

        'We'll start and stop the background worker using one button. We'll toggle
        'the button text as we change states between running to stopped.

        Dim btn As Button = sender

        If btn.Text = "Start" Then      'start the background thread
            btn.Text = "Stop"
            bgwPing.RunWorkerAsync()
        Else
            btn.Text = "Start"
            bgwPing.CancelAsync()       'tell the background thread to stop itself
        End If

    End Sub

    Private Sub UpdateStatus(text As String)

        'The InvokeRequired method returns True if the thread that calls it
        'is running from a different thread. In that case we create a delegate
        'to do the update of the control's text otherwise we can update the
        'text directly.

        If lblStatus.InvokeRequired Then
            Dim dlg As New UpdateStatusDelegate(AddressOf UpdateStatus)
            Me.Invoke(dlg, text)
        Else
            lblStatus.Text = TimeOfDay & " " & text
        End If

    End Sub

    Private Sub bgwPing_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgwPing.DoWork

        Do

            'If the foreground thread requested a cancellation then set the
            'appropriate flag and exit the loop.

            If bgwPing.CancellationPending Then
                e.Cancel = True
                Exit Do
            End If

            'do the ping and update the status label

            If My.Computer.Network.Ping(txtAddress.Text) Then
                UpdateStatus("Responding")
            Else
                UpdateStatus("Not Responding")
            End If

            'suspend for five seconds before the next ping

            System.Threading.Thread.Sleep(5000)

        Loop

    End Sub

End Class
Attachments 2012-11-18_15-14_BGPing.zip (69.7KB)
Reverend Jim
Carpe per diem
Moderator
3,600 posts since Aug 2010
Reputation Points: 561
Solved Threads: 447
Skill Endorsements: 32

u misunderstand me. i want to make a program like pinger, the free unlimited texting website. pinger.com/textfree forget it. its probably 2 advanced anyway. espacially for a begginer lik me.

Programmer629
Light Poster
35 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

I can see that that is considerably different from what I thought.

Reverend Jim
Carpe per diem
Moderator
3,600 posts since Aug 2010
Reputation Points: 561
Solved Threads: 447
Skill Endorsements: 32

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0722 seconds using 2.67MB