水如烟

                 顺其自然,水到渠成 LzmTW

文或代码皆是面向初学者.我是爱好者,也是初学者.那些"文章",只按自己理解写,我是不知术语名词的.所以只供参考,也仅供参考.

导航

HOW TO:Ping IP

Posted on 2005-12-19 12:52  水如烟(LzmTW)  阅读(254)  评论(0编辑  收藏  举报

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Console.WriteLine(Me.CheckIP("127.0.0.1"))
        Console.WriteLine(Me.CheckIP("127.0.0.2"))
        Console.WriteLine(Me.CheckIP("lzmtw.cnblogs.com"))
        Console.WriteLine(Me.CheckIP("LocalHost"))
        Console.WriteLine(Me.CheckIP("Localhost1"))
    End Sub

    Public Function CheckIP(ByVal NameOrIP As String) As Boolean
        Dim IsByIP As Boolean
        IsByIP = (NameOrIP.Split("."c).Length = 4)
        Try
            If IsByIP Then
                Console.WriteLine(System.Net.Dns.GetHostByAddress(NameOrIP).HostName)
            Else
                Console.WriteLine(System.Net.Dns.GetHostByName(NameOrIP).HostName)
            End If
            Return True
        Catch ex As System.Net.Sockets.SocketException
            Return False
        End Try
    End Function