Skip to content

atoonk/ping-aws-ips

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS EC2 ICMP Ping Utility

Description

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.

Key Features

  • 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.

ICMP and firewalls

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.

How to Run

To run this program, follow these steps:

  1. 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.
  2. 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.
  3. Running the Program:

    • Compile the program using go build -o ping-aws-ips.
    • Run the compiled binary. For example: ./ping-aws-ips.
  4. 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.
  5. 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.

Note

This utility is intended for monitoring purposes, not to abuse! Please use it responsibly.

About

ping all AWS IP addresses to see how many ec2 instances AWS has at any given time

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages