Slow Ping and not guaranteed success
-
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.IOPublic Class Form1
Dim reachable As Boolean = False
Dim IPEntry As IPHostEntry
Dim ReadAllLinesArray() As StringPublic 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
-
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.IOPublic Class Form1
Dim reachable As Boolean = False
Dim IPEntry As IPHostEntry
Dim ReadAllLinesArray() As StringPublic 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
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 -
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 KreskowiakI 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?
-
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?
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 -
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 -
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?
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 -
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?
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[^]