在 VB.net 中 Ping 机器列表 [英] Pinging a list of machines in VB.net

查看:22
本文介绍了在 VB.net 中 Ping 机器列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个机器列表,在一个名为 devices.txt 的文件中每行 1 个.

I have a list of machines, 1 per line in a file called devices.txt.

我需要做的是ping这些机器中的每一个,然后将每个在线的机器输出到另一个名为machines.txt的文本文件

What I need to be able to do is to ping each of these machines, and then output each machine that is online to another text file called machines.txt

文件只需是机器名称,每行有 1 台机器.

The files need to just be the machine name and have 1 machine per line.

谁能帮帮我?

推荐答案

类似的事情?

    Sub main()

    Dim results As New Dictionary(Of String, Boolean)

    Using myReader As System.IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader("c:\AllComputerNames.txt")

        Do While myReader.Peek() >= 0
            Dim computerName As String = myReader.ReadLine

            Debug.WriteLine(computerName, "Pinging computer :")

            results.Add(computerName, My.Computer.Network.Ping(computerName))

        Loop

    End Using

End Sub

编辑或如果您想将其写入文件:

Edit or if you want to write it to file :

        Using writer = My.Computer.FileSystem.OpenTextFileWriter("C:\ComputersOutput", False)

        Using myReader As System.IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader("c:\AllComputerNames.txt")

            Do While myReader.Peek() >= 0
                Dim computerName As String = myReader.ReadLine

                Debug.WriteLine(computerName, "Pinging computer :")

                writer.WriteLine(String.Join(" - ", computerName, My.Computer.Network.Ping(computerName)))

            Loop

        End Using

    End Using

这篇关于在 VB.net 中 Ping 机器列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆