Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Slow Ping and not guaranteed success

Slow Ping and not guaranteed success

Scheduled Pinned Locked Moved Visual Basic
csharpcomsysadminhosting
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Herboren
    wrote on last edited by
    #1

    I work for an ISP strictly for small business and minimal residential. We provide different services as well as web hosting. We have to convert web domains to an IP once a month from a list. I am trying to recreate an app in VB.net and it takes forever for ping result to come back as true or flase and when I transl;ate the host into an IP it doesnt get an IP for the host even though it exists. Here is a sample picture of my compiled app running: http://postimg.com/87000/what-86552.jpg[^] my code in vb.net:

    Imports System
    Imports System.Net
    Imports System.IO

    Public Class Form1
    Dim reachable As Boolean = False
    Dim IPEntry As IPHostEntry
    Dim ReadAllLinesArray() As String

    Public Function IsDestinationRechable(ByVal hostOrAddress As String)
        Try
            reachable = My.Computer.Network.Ping(hostOrAddress)
        Catch pingException As System.Net.NetworkInformation.PingException
        Catch genericNetworkException As System.Net.NetworkInformation.NetworkInformationException
            'Fail silently and return false
        End Try
        Return reachable
    End Function
    
    Public Sub GetPingAndIPv4()
        Try
    
            For Each s As String In ReadAllLinesArray
                Try
                    IPEntry = Dns.GetHostByName(s)
                    If IsDestinationRechable(IPEntry.AddressList(0).ToString) = True Then
                        Dim lsv As ListViewItem = lsvHostItemList.Items.Add(s)
                        lsv.SubItems.Add(IPEntry.AddressList(0).ToString)
                        lsv.SubItems.Add(IsDestinationRechable(reachable))
                       
                        tssProgressBar.PerformStep()
                    Else
                        Dim lsv As ListViewItem = lsvHostItemList.Items.Add(s)
                        lsv.SubItems.Add("n/a")
                        lsv.SubItems.Add(IsDestinationRechable(reachable))
                        tssProgressBar.PerformStep()
                    End If
                Catch ex As Exception
                End Try
            Next
    
        Catch ex As Exception
    
        End Try
    End Sub
    
    Private Sub OpenToolStripMenuItem\_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
        If OpenOldHostsFile.ShowDialog = Windows.Forms.DialogResult.OK Then
    
    D 1 Reply Last reply
    0
    • H Herboren

      I work for an ISP strictly for small business and minimal residential. We provide different services as well as web hosting. We have to convert web domains to an IP once a month from a list. I am trying to recreate an app in VB.net and it takes forever for ping result to come back as true or flase and when I transl;ate the host into an IP it doesnt get an IP for the host even though it exists. Here is a sample picture of my compiled app running: http://postimg.com/87000/what-86552.jpg[^] my code in vb.net:

      Imports System
      Imports System.Net
      Imports System.IO

      Public Class Form1
      Dim reachable As Boolean = False
      Dim IPEntry As IPHostEntry
      Dim ReadAllLinesArray() As String

      Public Function IsDestinationRechable(ByVal hostOrAddress As String)
          Try
              reachable = My.Computer.Network.Ping(hostOrAddress)
          Catch pingException As System.Net.NetworkInformation.PingException
          Catch genericNetworkException As System.Net.NetworkInformation.NetworkInformationException
              'Fail silently and return false
          End Try
          Return reachable
      End Function
      
      Public Sub GetPingAndIPv4()
          Try
      
              For Each s As String In ReadAllLinesArray
                  Try
                      IPEntry = Dns.GetHostByName(s)
                      If IsDestinationRechable(IPEntry.AddressList(0).ToString) = True Then
                          Dim lsv As ListViewItem = lsvHostItemList.Items.Add(s)
                          lsv.SubItems.Add(IPEntry.AddressList(0).ToString)
                          lsv.SubItems.Add(IsDestinationRechable(reachable))
                         
                          tssProgressBar.PerformStep()
                      Else
                          Dim lsv As ListViewItem = lsvHostItemList.Items.Add(s)
                          lsv.SubItems.Add("n/a")
                          lsv.SubItems.Add(IsDestinationRechable(reachable))
                          tssProgressBar.PerformStep()
                      End If
                  Catch ex As Exception
                  End Try
              Next
      
          Catch ex As Exception
      
          End Try
      End Sub
      
      Private Sub OpenToolStripMenuItem\_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
          If OpenOldHostsFile.ShowDialog = Windows.Forms.DialogResult.OK Then
      
      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The most common is your DNS infrastructure is taking forever to resolve the host name passed into the Ping method. There are anyn number of reasons for this, none which have anything to do with your code. Also, the default timeout for Ping to wait for a response is half a second, so I hope you don't mean that takes forever.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      H 1 Reply Last reply
      0
      • D Dave Kreskowiak

        The most common is your DNS infrastructure is taking forever to resolve the host name passed into the Ping method. There are anyn number of reasons for this, none which have anything to do with your code. Also, the default timeout for Ping to wait for a response is half a second, so I hope you don't mean that takes forever.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        H Offline
        H Offline
        Herboren
        wrote on last edited by
        #3

        I managed to figure out why, my next question is, why is my code not returning the IP and saying the site site is in active, and also when it returns an IP I type that IP in the browser and it doesn't take me to the domain that its assigned to. why? I guess I could see this as a security prevention but how do I get the right IP from it?

        D 1 Reply Last reply
        0
        • H Herboren

          I managed to figure out why, my next question is, why is my code not returning the IP and saying the site site is in active, and also when it returns an IP I type that IP in the browser and it doesn't take me to the domain that its assigned to. why? I guess I could see this as a security prevention but how do I get the right IP from it?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          All of this comes down to a screwed up DNS system. None of this is because of your code. If you give the DNS system host name and it returns the wrong IP, unless you're the administrator of the DNS system, there's nothing you can do about it. Either the correct IP is returned, or some proxy server for the browser to use is returned, or the data doesn't go to the correct machine. The other thing is that Ping is NOT a viable method for determining if a host is available or not. This is because firewalls may be between you and the host, blocking ICMP traffic or the host may be ignoring all ICMP traffic, even though the server and its web site are up and running and responding.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          H 1 Reply Last reply
          0
          • D Dave Kreskowiak

            All of this comes down to a screwed up DNS system. None of this is because of your code. If you give the DNS system host name and it returns the wrong IP, unless you're the administrator of the DNS system, there's nothing you can do about it. Either the correct IP is returned, or some proxy server for the browser to use is returned, or the data doesn't go to the correct machine. The other thing is that Ping is NOT a viable method for determining if a host is available or not. This is because firewalls may be between you and the host, blocking ICMP traffic or the host may be ignoring all ICMP traffic, even though the server and its web site are up and running and responding.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            H Offline
            H Offline
            Herboren
            wrote on last edited by
            #5

            Knowing I dont have the admin access what would be the viable method without seeming I am a threat to any system. If ICMP isnt going to work then how else would I go about converting the hostname into an IP using the best methods?

            D L 2 Replies Last reply
            0
            • H Herboren

              Knowing I dont have the admin access what would be the viable method without seeming I am a threat to any system. If ICMP isnt going to work then how else would I go about converting the hostname into an IP using the best methods?

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Without a known good authoritative DNS that knows about the target system you have no options. The only thing you need the DNS for is to resolve the hostname to an IP or the other way around. If you don't have a good DNS, you have no hope of matching up hostnames to IPs. ICMP is the protocol that Ping uses, not DNS. Ping sends an ICMP packet to the hostname or IP specified and waits for a response. If it gets one within the timeout period, the host is considered alive by Ping. If not, this is in no way an indication that the host is unavailable or down. It just means the packet either never got to the host because of a firewall blocking it (getting more and more common) or it's passing through some hop that filters out ICMP. Internally, Ping uses DNS to resolve a specified hostname to an IP. You can only talk to IP addresses, not hostnames. If DNS is wrong or not working properly, the Ping will be wrong too.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak

              1 Reply Last reply
              0
              • H Herboren

                Knowing I dont have the admin access what would be the viable method without seeming I am a threat to any system. If ICMP isnt going to work then how else would I go about converting the hostname into an IP using the best methods?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Perhaps a far-fetched alternative, but at least it's another option; You could setup OpenDNS[^] on a remote machine, and have that convert the IP to a host-name (using a webservice or whatever type of communication). You'd call the [Dns.GetHostByAddress](http://msdn.microsoft.com/en-us/library/sbetxfzt.aspx)[[^](http://msdn.microsoft.com/en-us/library/sbetxfzt.aspx "New Window")]-member, and return the host-name.

                Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups