This is a simple tool that tries to detect if the provided ip is anycasted or not.
Taken from wikipedia
Anycast is a network addressing and routing methodology in which a single IP address is shared by devices (generally servers) in multiple locations. Routers direct packets addressed to this destination to the location nearest the sender.
Simply put, multiple servers in different locations share the same IP and any of them can respond to the request sent to this IP.
This is a tough problem and there are not straight forward solutions, unless you know the routing tables of majour ISPs. My solution puts different servers at different locations, pinging the target IP address and checking if the request RTT (round trip time) beats the speed of light.
- False postives are not possible
- False negatives are likely
Example
configuration:
1. Server #1 in Europe in germany
2. Server #2 in USA in california
target: google dns 8.8.8.8
server #1 responds in 19ms
server #2 responds in 18ms
knowing the locations of these servers, the minimum latency assuming straight line and speed of light is 61ms
The IP address is definitely an Anycast
npm install
npm run dev
I am using aws lambda (serverless) for deployment. you can use the serverless.yaml (serverless framework) to deploy your own versions That is why I am using tcp ping instead of regular ICMP
example .env
SERVERS=http://server1.test|http://server2.test
THIS_SERVER=http://server1.test
INTERNAL_API_KEY=SECRET_PASSWORD_USED_ACROSS_NODES
The application has to have multiple nodes to be able to detect anycast IP addresses. each node has a list of the available nodes
Every node supports these simple operations:
- Reporting it's own geo location using ip-api.com
- Pinging an IP address
- Broadcasting to the other nodes
All of these operations are secured used a token/password. Then each node exposes a simple api call publicly to detect anycasts.
- the hit node calls other nodes to get their geo location (cached)
- Broadcast the ping request to available nodes (including itself)
- Wait for coming latency results. If any node latency beats the speed of light, the call returns.
First of all, cool. The tool will work however the result may be incorrect because the domain name is likely using DNS loadbalancing