VB.NET覚書

VB.NETの覚書
[個人メモ] [仕事メモ] [アイデア] [Ruby]
[TIPS] [対応表] [コメント書き方] [.NET Tips] [VB中学校] [VB.NET の入門サイト] [VB.NET コーディング標準 ] [VBレスキュー] [NonSoft]

2014-07-10

Ping

Module Module1

    Sub Main()

        'Pingオブジェクトの作成
        Dim p As New System.Net.NetworkInformation.Ping()
        '"www.yahoo.com"にPingを送信する
        Dim reply As System.Net.NetworkInformation.PingReply = p.Send("www.yahoo.com")

        '結果を取得
        If reply.Status = System.Net.NetworkInformation.IPStatus.Success Then
            Console.WriteLine("Reply from {0}:bytes={1} time={2}ms TTL={3}", reply.Address, reply.Buffer.Length, reply.RoundtripTime, reply.Options.Ttl)
        Else
            Console.WriteLine("Ping送信に失敗。({0})", reply.Status)
        End If

        p.Dispose()

    End Sub

End Module
Module Module1

    Sub Main()

        Dim i As Integer

        'Pingオブジェクトの作成
        Dim p As New System.Net.NetworkInformation.Ping()
        '"www.yahoo.com"にPingを送信する
        Dim reply As System.Net.NetworkInformation.PingReply

        For i = 1 To 255
            reply = p.Send("133.100.30." & Trim(Str(i)))

            '結果を取得
            If reply.Status = System.Net.NetworkInformation.IPStatus.Success Then
                Console.WriteLine("Reply from {0}:bytes={1} time={2}ms TTL={3}", reply.Address, reply.Buffer.Length, reply.RoundtripTime, reply.Options.Ttl)
            Else
                Console.WriteLine("Ping送信に失敗。({0})", reply.Status)
            End If

        Next
        p.Dispose()

    End Sub

End Module
トラックバック - http://sub.g.hatena.ne.jp/garyo/20140710