pinging websites via vb.net 
Author Message
 pinging websites via vb.net

I would like to programmatically ping websites to monitor them (not
maliciously).  In the past with vb6 I have used the Inet control with code
like this

Dim sDocument As String
    sDocument = Inet1.OpenURL(sURL, icString)
    ServerIsResponding = (Len(sDocument) > 0)

But there doesn't seem to be a .net version of microsoft internet controls.

Does anyone have an alternative?

Jon



Mon, 19 Jan 2004 02:54:21 GMT  
 pinging websites via vb.net
You could just create a webrequest.  There are examples in the SDK
helpfiles....I have attached one for you below to pick apart.

Regards

John Timney (Microsoft MVP)
----------------------------------------------
<author plug>
Professional JSP
    ISBN: 1861003625
Beginning JSP
    Out Soon
Professional Windows Forms
    Out Soon
</author plug>
----------------------------------------------

Imports SystemImports System.Net
Imports System.IO
Imports System.Text

Namespace Client
    Public class ClientGET
        Public Shared bShow As Boolean

        Public Shared Sub   Main()

            Dim args As String ()
            Dim Url As String
            args = Environment.GetCommandLineArgs()

            If (args.Length < 2)
                showusage()
            Else
                If (args.Length = 3)
                    bShow = False
                Else
                    bShow = True
                End If

                getPage(args(1))
            End If

            Console.WriteLine()
            Console.WriteLine("Press Enter to continue...")
            Console.ReadLine()

            Return
        End Sub

        public Shared Sub showusage()
            Console.WriteLine("Attempts to GET a URL")
            Console.WriteLine()
            Console.WriteLine("Usage:")
            Console.WriteLine("ClientGET URL")
            Console.WriteLine()
            Console.WriteLine("Examples:")
            Console.WriteLine("ClientGET http://www.microsoft.com/net/")
        End Sub

        public Shared Sub getPage(url As String)
            Try
                Dim req As WebRequest
                Dim result As WebResponse
                Dim ReceiveStream As Stream
                Dim encode As Encoding
                Dim sr As StreamReader

                req = WebRequest.Create(url)
                result = req.GetResponse()
                ReceiveStream = result.GetResponseStream()
                encode = System.Text.Encoding.GetEncoding("utf-8")
                sr = new StreamReader( ReceiveStream, encode )

                Console.WriteLine()
                Console.WriteLine("Response stream received")
                If bShow
                    Dim read(256) As Char
                    Dim count As Integer = sr.Read( read, 0, 256 )

                    Console.WriteLine("HTML...")
                    Console.WriteLine()
                    Do While count > 0
                        Dim str As String = new String(read, 0, count)
                        Console.Write(str)
                        count = sr.Read(read, 0, 256)
                    Loop
                    Console.WriteLine("")
                End If
            Catch Exc As Exception
                Console.WriteLine()
                Console.WriteLine("The request URI could not be found or was
malformed")
            End Try
        End Sub
    End Class
End Namespace



Mon, 19 Jan 2004 03:31:11 GMT  
 pinging websites via vb.net
Thanks a lot John! I'll give it a try.
Jon



Quote:
> You could just create a webrequest.  There are examples in the SDK
> helpfiles....I have attached one for you below to pick apart.

> Regards

> John Timney (Microsoft MVP)
> ----------------------------------------------
> <author plug>
> Professional JSP
>     ISBN: 1861003625
> Beginning JSP
>     Out Soon
> Professional Windows Forms
>     Out Soon
> </author plug>
> ----------------------------------------------

> Imports SystemImports System.Net
> Imports System.IO
> Imports System.Text

> Namespace Client
>     Public class ClientGET
>         Public Shared bShow As Boolean

>         Public Shared Sub   Main()

>             Dim args As String ()
>             Dim Url As String
>             args = Environment.GetCommandLineArgs()

>             If (args.Length < 2)
>                 showusage()
>             Else
>                 If (args.Length = 3)
>                     bShow = False
>                 Else
>                     bShow = True
>                 End If

>                 getPage(args(1))
>             End If

>             Console.WriteLine()
>             Console.WriteLine("Press Enter to continue...")
>             Console.ReadLine()

>             Return
>         End Sub

>         public Shared Sub showusage()
>             Console.WriteLine("Attempts to GET a URL")
>             Console.WriteLine()
>             Console.WriteLine("Usage:")
>             Console.WriteLine("ClientGET URL")
>             Console.WriteLine()
>             Console.WriteLine("Examples:")
>             Console.WriteLine("ClientGET http://www.microsoft.com/net/")
>         End Sub

>         public Shared Sub getPage(url As String)
>             Try
>                 Dim req As WebRequest
>                 Dim result As WebResponse
>                 Dim ReceiveStream As Stream
>                 Dim encode As Encoding
>                 Dim sr As StreamReader

>                 req = WebRequest.Create(url)
>                 result = req.GetResponse()
>                 ReceiveStream = result.GetResponseStream()
>                 encode = System.Text.Encoding.GetEncoding("utf-8")
>                 sr = new StreamReader( ReceiveStream, encode )

>                 Console.WriteLine()
>                 Console.WriteLine("Response stream received")
>                 If bShow
>                     Dim read(256) As Char
>                     Dim count As Integer = sr.Read( read, 0, 256 )

>                     Console.WriteLine("HTML...")
>                     Console.WriteLine()
>                     Do While count > 0
>                         Dim str As String = new String(read, 0, count)
>                         Console.Write(str)
>                         count = sr.Read(read, 0, 256)
>                     Loop
>                     Console.WriteLine("")
>                 End If
>             Catch Exc As Exception
>                 Console.WriteLine()
>                 Console.WriteLine("The request URI could not be found or
was
> malformed")
>             End Try
>         End Sub
>     End Class
> End Namespace



Mon, 19 Jan 2004 03:55:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Access to companie website via VB 5.0 application

2. How can I ping a website ?

3. How can I ping a website ?

4. Packing a FoxPro table via ODBC.net from VB.net

5. Ping in Vb.net

6. ICMP in VB .NET? (ICMP=Ping)

7. Ping in VB.net

8. How to ping with VB.NET

9. Adding websites to link labels in VB.NET

10. Any good VB.NET websites?

11. Website using VB.NET

12. VB.NET websites?

 

 
Powered by phpBB® Forum Software