Suppose I want to determine if an IP is located in my country, without a third-party servvice. Could I estimate that to a certain degree by measuring ping times? Or is it better to look at the number of hops in the trace route? Or something else?
Yes there is certainly a correlation between ping time and distance. However there are many factors other than distance that can lead to a high ping. Congestion, crappy routing, Satellite links etc.
So attempting to use ping time as a geoblocking measure is likely to have an unacceptably high false positive rate.
Short answer: No.
Long answer: IP addresses aren't determined by geographical reason insomuch as the geographical region simply might only have a certain block assigned to it.
Example: North Korea has a relatively small block of IP addresses, which makes it easy to tell when someone from that country has visited your website.
In the case of the USA, France, Germany, South Korea, Japan or others, the number of IP blocks assigned to their ISPs is much greater, so simply glancing at an IP to see if it starts with a certain number won't necessarily guarantee that that entire network is assigned to a single geographical region.
With regards to ping times, ping time is determined by a great number of factors, including but not limited to:
- Number of routers between you and the target you are pinging
- Networking problems in-between you and the target
- Excessive traffic / congestion between you and the target
Example: I can ping Google's root DNS server 18.104.22.168 from my home internet and get about 40ms, through 12 (!) hops, yet I get a under-1ms ping to 22.214.171.124 from another location in the same city, from a different ISP, on a faster connection, through only four hops.
Ping time is directly related to maximum cable length the signal can go until it reaches destination IP. Formula for calculating maximum cable length in km by ping time is:
So if your ping command for example displays a 2.18 ms ping, then this means that signal could travel at maximum 327 km through cable until destination. But this is just an upper-limit of cable length. In reality there are a lot of different factors which affects signal round-trip time. For example signal in fiber optics experiences less signal loss than in copper wires, so in fiber wires it is needed much smaller amount of signal amplifiers,- which may induce additional latency too. Damaged cables, bandwidth load in line and etc, etc. And thus real cable length penetrated by signal in half-time of ping is much smaller, because signal "feels" resistance of many kinds.