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:
Dim reachable AsBoolean = FalseDim IPEntry As IPHostEntry
Dim ReadAllLinesArray() AsStringPublicFunction IsDestinationRechable(ByVal hostOrAddress AsString)
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
TryForEach s AsStringIn ReadAllLinesArray
IPEntry = Dns.GetHostByName(s)
If IsDestinationRechable(IPEntry.AddressList(0).ToString) = TrueThenDim lsv As ListViewItem = lsvHostItemList.Items.Add(s)
ElseDim lsv As ListViewItem = lsvHostItemList.Items.Add(s)
EndIfCatch ex As Exception
EndTryNextCatch ex As Exception
EndTryEndSubPrivateSub OpenToolStripMenuItem_Click(sender AsObject, e As EventArgs) Handles OpenToolStripMenuItem.Click
If OpenOldHostsFile.ShowDialog = Windows.Forms.DialogResult.OK Then
ReadAllLinesArray = File.ReadAllLines(OpenOldHostsFile.FileName)
tssProgressBar.Maximum = ReadAllLinesArray.Count
EndIfEndSubPrivateSub SaveToolStripMenuItem_Click(sender AsObject, e As EventArgs) Handles SaveToolStripMenuItem.Click
If SaveNewHostsFile.ShowDialog = Windows.Forms.DialogResult.OK ThenEndIfEndSubPrivateSub ExitToolStripMenuItem_Click(sender AsObject, e As EventArgs) Handles ExitToolStripMenuItem.Click
EndEndSubPrivateSub RunToolStripMenuItem1_Click(sender AsObject, e As EventArgs) Handles RunToolStripMenuItem1.Click
My code isn't complete I am trying to get the main functionality working correctly first.
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.
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.
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.
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[^]-member, and return the host-name.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
Last Visit: 31-Dec-99 19:00 Last Update: 19-Apr-15 5:24