locked
How to ping website from my code RRS feed

  • Question

  • I'm doing a small program for testing network connectivity
    All My work is ok but the only problem I'm facing is the code

    Res = My.Computer.Network.Ping(txtComputerName.Text).ToString

    it's working ok on my local network and give me good results
    but when I try to ping a web site it gives me error



    note that I can access the internet through an ISA server 2006 and can't connect my computer directly to the router
    Tuesday, July 31, 2018 5:49 AM

All replies

  • Hi

    I think it may be that the ping port on the computer may be down, or the firewall or router may have blocked the ping request.

    https://docs.microsoft.com/en-gb/previous-versions/visualstudio/visual-studio-2008/he5sca5t(v=vs.90)

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 31, 2018 8:04 AM
  • please read the note at the end of my question

    I have ISA server that provide internet to the network that means to connect to internet I need (proxy + credentials) to be passed correctly to ping command to be executed correctly that is what I failed to do

    Tuesday, July 31, 2018 8:29 AM
  • For HTTP proxy for a valid connection maybe you could try the following API 

    WebRequest.Proxy Property

       ' Create a new request to the mentioned URL.				
            Dim myWebRequest As WebRequest = WebRequest.Create("http://www.contoso.com")
            Dim myProxy As New WebProxy()
    
            ' Obtain the Proxy Prperty of the  Default browser. 
             myProxy = CType(myWebRequest.Proxy, WebProxy)
    
            ' Print myProxy address to the console.
            Console.WriteLine(ControlChars.Cr + "The actual default Proxy settings are {0}", myProxy.Address)
    
            Try
                Console.WriteLine(ControlChars.Cr + "Please enter the new Proxy Address to be set ")
                Console.WriteLine("The format of the address should be http://proxyUriAddress:portaddress")
                Console.WriteLine("Example:http://moon.proxy.com:8080")
                Dim proxyAddress As String
                proxyAddress = Console.ReadLine()
    
                If proxyAddress.Length = 0 Then
                    myWebRequest.Proxy = myProxy
                Else
                    Console.WriteLine(ControlChars.Cr + "Please enter the Credentials")
                    Console.WriteLine("Username:")
                    Dim username As String
                    username = Console.ReadLine()
                    Console.WriteLine(ControlChars.Cr + "Password:")
                    Dim password As String
                    password = Console.ReadLine()
    
                   ' Create a new Uri object.
                    Dim newUri As New Uri(proxyAddress)
    
                    ' Associate the new Uri object to the myProxy object.
                    myProxy.Address = newUri
    
                    ' Create a NetworkCredential object and is assign to the Credentials property of the Proxy object.
                    myProxy.Credentials = New NetworkCredential(username, password)
                    myWebRequest.Proxy = myProxy
    
                End If
                Console.WriteLine(ControlChars.Cr + "The Address of the  new Proxy settings are {0}", myProxy.Address)
                Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
    
                ' Print the  HTML contents of the page to the console.
                Dim streamResponse As Stream = myWebResponse.GetResponseStream()
    
                Dim streamRead As New StreamReader(streamResponse)
                Dim readBuff(256) As [Char]
                Dim count As Integer = streamRead.Read(readBuff, 0, 256)
                Console.WriteLine(ControlChars.Cr + "The contents of the Html pages are :")
    
                While count > 0
                    Dim outputData As New [String](readBuff, 0, count)
                    Console.Write(outputData)
                    count = streamRead.Read(readBuff, 0, 256)
    
                End While
    
        ' Close the Stream object.
                streamResponse.Close()
    streamRead.Close()
    
       ' Release the HttpWebResponse Resource.
         myWebResponse.Close()
                Console.WriteLine(ControlChars.Cr + "Press any key to continue.........")
                Console.Read()
            Catch e As UriFormatException
                Console.WriteLine(ControlChars.Cr + "{0}", e.Message)
                Console.WriteLine(ControlChars.Cr + "The format of the myProxy address you entered is invalid")
             End Try


    remember make the reply as answer and vote the reply as helpful if it helps.

    Tuesday, July 31, 2018 9:21 AM
  • Invalid Cast at line
    myProxy = CType(myWebRequest.Proxy, WebProxy)


    Tuesday, July 31, 2018 10:47 AM
  • I'm doing a small program for testing network connectivity
    All My work is ok but the only problem I'm facing is the code

    Res = My.Computer.Network.Ping(txtComputerName.Text).ToString

    it's working ok on my local network and give me good results
    but when I try to ping a web site it gives me error



    note that I can access the internet through an ISA server 2006 and can't connect my computer directly to the router

    WHY do you need to ping a website?  Do you or your company own the website?


    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it."

    - from former MSDN User JohnWein

    SerialPort Info

    Multics - An OS ahead of its time.

    Tuesday, July 31, 2018 4:22 PM
  • I agree with dbasnett… why ping a web server?  First it tells you nothing about the state of the site (the server might respond, but that does not mean that the site is up and running), and second the server may very well block ICMP requests from outside sources (typical security to prevent denial of service attacks).

    It would be much better to create a WebRequest to attempt to access the default web page for this website.  If that request succeeds, you know that the website is responding.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, July 31, 2018 6:39 PM
  • I need to know if the computer I've working on using a certain account has internet access because not all users have right to access internet ( I have ISA Server controlling that )


    some friend gives me code using INetworkListManager::GetConnectivity  but it gives me that there is access form account have not access to internet

    I welcome any solution


    about using application.doevents you are right the better way is to execute my code on another thread I'll do that thank you

    Wednesday, August 1, 2018 7:01 AM