Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Ping machines from list and update .txt file

Posted on 2009-07-07
4
Medium Priority
?
698 Views
Last Modified: 2013-11-27
Hi Guys,

I need some help getting started with this, I have only just downloaded VB E 2008 and realised I cant update my old VB6 apps with it. So I need to start form scratch with this one.

I need a simple application to ping a list of machines listed in a .txt file, then update the .txt to file to state if ping was succesful or not.

I have got about 500 machines on a network at work and I want to see how many are left on through the night by running this, if they are on I will send a shutdown commmand. Before you ask they are not on a domain so I cant do this via a GP.

As always thanks for your help guys.
0
Comment
Question by:pnorris99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 640 total points
ID: 24794316
1) Use a stream reader to read your list of computers to ping
-- http://msdn.microsoft.com/en-us/library/yw67h925%28VS.80%29.aspx

2) Send a ping to the computer listed on each line as you loop through the stream reader
-- http://www.aspnettutorials.com/tutorials/network/net-ping-aspnet2-vb.aspx (vb example at the bottom)

3) Store the ping results for active computers to an arraylist (or text file and stream read again)

4) Loop through arraylist (or text file via stream reader) and send shutdown command.
0
 
LVL 41

Assisted Solution

by:graye
graye earned 640 total points
ID: 24843446
If you're interested in a complete example in VB.Net, take a look at the following:
http://www.emmet-gray.com/Programs/PCsOnline.zip 
0
 

Assisted Solution

by:emresamisuzer
emresamisuzer earned 640 total points
ID: 24893673
I have written a small program to like you need. I think it will help you... This won't update the text file but create an xml report about the ping results. You need to have a dataset also!

<?xml version="1.0" standalone="yes"?>
<PingTest xmlns="http://tempuri.org/PingTest.xsd">
  <Pings>
    <Timestamp>2009-07-20T13:16:13.0986384+03:00</Timestamp>
    <Host>www.google.com</Host>
    <Response>189</Response>
    <Status>true</Status>
  </Pings>
</PingTest>
Imports System.Net
Imports System.Net.NetworkInformation
Imports System.ComponentModel
 
Public Class Form1
 
    Private p As New Ping
    Private WithEvents workers As New List(Of BackgroundWorker)
    Private sets As New List(Of PingTest)
    Private hosts As New Hashtable
    Private cancel As Boolean = True
 
    Private Function PingIt(ByVal host As String) As PingReply
        Return p.Send(host)
    End Function
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ofd As New OpenFileDialog
        ofd.Filter = "Text Files (*.txt)|*.txt"
        If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
            If ofd.FileName.Length > 0 Then
                If ofd.FileName.EndsWith(".txt") Then
                    TextBox1.Text = ofd.FileName
                End If
            End If
        End If
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Label3.Text = Now.ToString
        Button2.Enabled = False
        Button3.Enabled = Not Button2.Enabled
        cancel = False
        workers.Clear()
        sets.Clear()
        hosts.Clear()
        Try
            Dim hs() As String = System.IO.File.ReadAllText(TextBox1.Text).Split(vbLf)
            For h As Integer = 0 To hs.Length - 1
                If hs(h).Trim.Length > 0 Then
                    hosts.Add(h, hs(h).Trim)
                    workers.Add(New BackgroundWorker())
                    sets.Add(New PingTest)
                    AddHandler workers(h).DoWork, AddressOf DoJob
                    workers(h).RunWorkerAsync(New Object() {h})
                End If
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
            Button2.Enabled = True
            Button3.Enabled = Not Button2.Enabled
        End Try
    End Sub
 
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        cancel = True
        Button2.Enabled = True
        Button3.Enabled = Not Button2.Enabled
    End Sub
 
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        For s As Integer = 0 To sets.Count - 1
            sets(s).WriteXml(My.Application.Info.DirectoryPath & "\" & hosts(s) & ".xml")
        Next
        MsgBox("Exported")
    End Sub
 
    Private Sub DoJob(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
        While Not cancel
            Dim rep As PingReply = PingIt(hosts(e.Argument(0)))
            sets(e.Argument(0)).Pings.AddPingsRow(Now, hosts(e.Argument(0)), rep.RoundtripTime, rep.Status = IPStatus.Success)
            System.Threading.Thread.Sleep(NumericUpDown1.Value)
        End While
    End Sub
 
 
 
End Class

Open in new window

0
 
LVL 1

Author Closing Comment

by:pnorris99
ID: 31600566
Thanks guys
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question