I have written simple code to determine country location using the suffix on the url eg. .cn, .se, .br etc.
Does anyone have any ideas or even if its possible to determine country or location using urls that end in .com or .net?
I was just reading up on something and found online apps that can determine location/country from the ip so how would I determine the ip or look it up using the url? can I do this in .net?
OK
So I have the following code and I get an exception when the url is invalid or faulty, can anyone help me to catch the error and add the url to another list and continue with my loop.
Public Sub getIpAddress(ByVal querylist As ArrayList)
Dim IPList As New ArrayList
Dim badList As New ArrayList
Dim badHost As String
Try
For Each prod In querylist
开发者_如何学编程 Dim ipEntry As IPHostEntry = Dns.GetHostEntry(prod)
Dim IPAdd As IPAddress() = ipEntry.AddressList
IPList.Add(IPAdd.ToString)
Next
Catch ex As Exception
If ex.Message.Contains("No such host is known?") Then
End If
End Try
End Sub
You could easily use an IP-to-country mapping file such as this to build a little tool to infer location from the IP. I would also supplement this with the TLD of country specific domains such as .co.uk and .co.nz.
You can get the IP from the host name in java using something like:
InetAddress addr = InetAddress.getByName("www.bbc.co.uk");
Long ipNum = ipToInt(addr.getHostAddress());
You'll have to map to the equivalent in your language.
If it is .net or .com you cannot read the location from the url.
You can read the language of the browser, see http://www.west-wind.com/weblog/posts/334.aspx
You could also read the IP address of request, and then use a location service to find where the request came from.
Not from the URL, but from the IP, you can do this. There are publicly available files which map an IP range to a country.
Note that the location within a country is quite hard to get, as you can only know the address of an ISP, not of a Web site.
You can determine the country where the servers are located.
You can find out the location of the domain registrar.
But then, the company or a person behind the site may live in some third place.
Whose geolocation are you trying to find out?
精彩评论