This Go program is designed to identify active (ICMP responsive) EC2 instances in AWS. It fetches the current IP ranges allocated for EC2 services from AWS, sends ICMP Echo Requests to these IPs, and records the IPs that respond. This utility showcases the power of asynchronous operations in network programming, where the main thread sends the packets, and a separate go routine is responsible for receiving packets. This means we don't have to rely on timeouts and due to this async nature can execute faster.
- ICMP Echo Request Sender: Sends ICMP Echo Requests to a list of IP addresses within the specified AWS EC2 IP ranges. As defined by AWS https://ip-ranges.amazonaws.com/ip-ranges.json
- Efficient Resource Utilization: By decoupling the sending and receiving processes, the program efficiently utilizes network and system resources. It can continue sending requests while concurrently processing incoming replies.
- Active Instance Detection: Identifies active EC2 instances by recording the IPs that respond to the ICMP Echo Requests.
- Configurable Rate Limit: The rate of ICMP requests can be configured, allowing control over network traffic generated by the utility.
- Results Logging: The IPs that respond are logged into a file, providing a record of all active instances detected during the program's run.
- IP Shuffling: The code randomizes the order of IP addresses before sending ICMP requests. This shuffling helps with Load Distribution: It prevents network load spikes by evenly distributing requests across different network segments or servers. Randomizing the order helps avoid patterns that might be flagged by various systems.
Remember that many ec2 instances and other services will have strict security groups and, by default, won't respond to a ping packet. As a result, the final number reported by this program is just a subset of the actual number of alive EC2 instances.
To run this program, follow these steps:
-
Prerequisites:
- Ensure you have Go installed on your system. You can download and install Go from here.
- Internet access is required for the program to fetch AWS IP ranges and to send ICMP requests.
-
Setting the Rate Limit:
- The default rate limit is set to 20,000 ICMP Echo Requests per second.
- You can configure the rate limit by modifying the
ratelimit
variable in the code.
-
Running the Program:
- Compile the program using
go build -o ping-aws-ips
. - Run the compiled binary. For example:
./ping-aws-ips
.
- Compile the program using
-
Output:
- The program will print the responding IPs to a file named
ping_results_<timestamp>.txt
. - The
<timestamp>
in the filename ensures that each run generates a unique file.
- The program will print the responding IPs to a file named
-
Interrupt Handling:
- If the program is interrupted (e.g., via Ctrl-C), it will still finalize and write the results to the output file before exiting.
This utility is intended for monitoring purposes, not to abuse! Please use it responsibly.