How to determine the distance between two computers by their IP adress

Started by
5 comments, last by frob 13 years, 3 months ago
Hi all,
I'm a newbie in network. I'd like to know if it's far or near between two computers, by their IP adress or by their ping value( the latency between them)?
Can anyone tell me these in detail?
Thanks in advance!
Advertisement
The only effect distance has on ping time is the lower bound - two computers X km apart cannot have ping time less than Y, bounded by speed of light and length of wire connecting them. For example: s = 300000km/s*0.65 * 0.147s = 28665 / 2 ~= 14300km. So ping of 147ms would mean that servers are connected with at most 14300km of fiber. Actual distance will be much shorter.

Other than that, due to latency of network stack processing, different priorities, different routes, different bandwidth, ping isn't closely related to distance. For example, it's not uncommon for intercontinental connections to have lower ping times than intracontinental, especially for high profile sites - they simply sit directly on the backbone, while smaller sites are deep within data centers on oversubscribed and virtualized systems.
In addition, if you simply have the IP addresses of two computers (without access to one or the other), you could only determine the ping from your computer to theirs. This would get you an (approximate) upper bound of the sum of the pings for the ping between the two computer, but in reality it could be significantly lower.

However, there are IP-lookup sites which try to give geographic locations to IP addresses. They're not great (eg: mine comes up as the nearest major city, which is over 50 miles away), but if you only need very general locations you can try them and some IPs will come up very precisely. For example, here's one.
Simply using ping is not going to work as Antheus mentioned. Ezbez is correct and it's really the only way you can do it. Note that even this isn't 100% accurate because if someone uses a proxy or another trick then it's a lot harder to tell where they're coming from, if at all.

Here is an easy method to get you started though:
1) Get the Geolocation via IP address (This is a cheap way. If you are serious about this then you will need to buy a Geolocation database that has all of this information in it).

2) Calculate the distance based on the latitude and longitude points.


If you are programming smart devices then they will have something in the API for obtaining the locations. For instance, GPS will give you the latitude and longitude points.
There are a number of companies that provide exactly this service. Maxmind is one of the cheapest, but also one of the least accurate. Banks that do shopping fraud controls will use some of the higher-end providers.

If you want to get started with a free service for smaller volumes (less than 1k queries per day) you can try geoio.com
To reduce the number of calls, you can cache the look-up based on a class C mask, and store for some time (say, four weeks).
enum Bool { True, False, FileNotFound };
Thank you very much, hplus0603,UltimaX,Ezbez,Antheus.
Ask another question, how to select the nearest node in the P2P network? Which is the criterion? the latency?
Thanks.
Quote:Original post by skyman_cn
Thank you very much, hplus0603,UltimaX,Ezbez,Antheus.
Ask another question, how to select the nearest node in the P2P network? Which is the criterion? the latency?
Thanks.

It depends on your usage.

You may prefer a higher bandwidth or a lower latency for your particular application. If you are trying to get a small amount of data to a destination rapidly, prefer low latency. If you are trying to get a large amount of data rapidly, prefer high bandwidth.

In a P2P environment, you should also be concerned about connectivity. You may have a nearby node with great bandwidth and low latency, but it may be no good for peers if the node is unable to talk to others. This can be the case for a node living in a network DMZ; You may be able to see a very fast connection to a local network node, but that node is completely useless to the outside world.


It takes a little bit of computer science work, but you can create connectivity graphs that are shared across the P2P network. This can be important for partially connected networks where you need to figure out your own routing.

This topic is closed to new replies.

Advertisement