Skip to content

This Python-based ARP Simulator implements a client-server model to demonstrate the Address Resolution Protocol (ARP) in a local network environment. Using a predefined network dictionary with IP and MAC address pairs, the server responds to MAC address queries while the client sends requests and updates its ARP table.

Notifications You must be signed in to change notification settings

breezy-codes/ARP-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ARP Simulator Program

Introduction

This project provides a simple client-server model to simulate the ARP (Address Resolution Protocol) process in a local network environment. ARP is a protocol used to find the hardware (MAC) address of a device from its IP address.

Network Dictionary

To facilitate understanding and simulation, here's a sample network dictionary that represents a hypothetical local network with IP and MAC address pairs:

NETWORK = {
    '192.168.1.1': '00:0A:95:9D:68:16',
    '192.168.1.2': '00:0A:95:9D:68:17',
    '192.168.1.3': '00:0A:95:9D:68:18',
    '192.168.1.4': '00:0A:95:9D:68:19',
    '192.168.1.5': '00:0A:95:9D:68:1A',
    '192.168.1.6': '00:0A:95:9D:68:1B',
    '192.168.1.7': '00:0A:95:9D:68:1C',
    '192.168.1.8': '00:0A:95:9D:68:1D',
    '192.168.1.9': '00:0A:95:9D:68:1E',
    '192.168.1.10': '00:0A:95:9D:68:1F',
}

This dictionary plays a pivotal role in the ARP simulation where the server uses it to respond to MAC address queries for given IPs.

Purpose

  • To understand and simulate the ARP process in controlled environments.
  • To help visualize and practice network programming using Python's socket module.
  • Great for educational purposes, especially for those learning about networking and ARP operations.

Getting Started

https://youtu.be/A230IEK4OWA

Requirements

  • Python 3.x

Setting Up

  1. Clone this repository:
git clone [repository_link]
  1. Navigate to the project directory:
cd path_to_directory

Running the Simulator

  1. Start the ARP server:
python server.py

After running the command, you should see the message "ARP server is listening...".

  1. In a separate terminal, start the ARP client:
python client.py

You'll be prompted with "Enter IP to ARP for:".

  1. Enter any IP from the list (e.g., 192.168.1.1), and the client will display the associated MAC address.

Building from the Code

The code provided above has two main segments: the ARP server and the ARP client.

  1. ARP Server:

    • It binds to a specific IP (127.0.0.1) and port (65432).
    • Listens for incoming client requests.
    • For each received IP address, the server checks the NETWORK dictionary to fetch the associated MAC address.
    • Responds to the client with the MAC address or a "Not Found" message.
  2. ARP Client:

    • Connects to the server.
    • Takes IP address input from the user.
    • Sends the IP address to the server and waits for a response.
    • Updates its ARP table with the received MAC address.

To build your ARP simulator, you can expand upon this code by:

  • Making the NETWORK dictionary dynamic, allowing addition/removal of IP-MAC pairs.
  • Implementing a GUI for a more interactive experience.
  • Simulating multiple clients sending ARP requests simultaneously.

In-Depth Explanation

ARP Server

Purpose: The server simulates a small network segment. It possesses a dictionary (NETWORK) of IP addresses mapped to their corresponding MAC addresses. This simulator allows you to understand how ARP tables are built and how they collect the MAC addresses when pinged, without the need to ping actual devices on your network.

Key Components:

  1. Network Dictionary (NETWORK):
    This dictionary contains a pre-defined set of IP and MAC address pairs. It represents a hypothetical local network where devices' IP and MAC addresses are known.

  2. Socket Initialization:
    The code initializes a socket using the socket.AF_INET address family (IPv4) and the socket.SOCK_STREAM socket type (TCP).

  3. Bind and Listen:
    The server binds to a specified IP address and port. It then listens for incoming connections. This simulates the ARP server's readiness to receive ARP requests from clients.

  4. Connection Handling:
    Upon accepting a connection, the server retrieves the IP address sent by the client, searches the NETWORK dictionary, and sends back the corresponding MAC address, or 'Not Found' if the IP isn't present in the dictionary.

ARP Client

Purpose: The client simulates a device in the network that wishes to resolve an IP address to a MAC address.

Key Components:

  1. ARP Table (ARP_TABLE):
    This is the client's ARP cache. Initially empty, it gets populated as the client resolves IP addresses.

  2. User Input:
    The client prompts the user for an IP address that it wants to resolve.

  3. Socket Communication:
    The client uses a socket to send the input IP to the server and awaits a response.

  4. Table Update:
    Based on the server's response, the client updates its ARP table.

Improvements and Extensions:

  1. Dynamic Network Dictionary:
    Instead of hardcoding the IP-MAC pairs, one can integrate a simple database or use a configuration file that the server reads upon startup.

  2. Error Handling:
    Implement error handling to manage scenarios such as server unavailability, incorrect IP format, etc.

  3. Logging:
    Introduce a logging mechanism for both client and server to track and record events, which can be useful for debugging and understanding the flow of operations.

  4. Multi-threading:
    Allow the server to handle multiple client requests simultaneously by implementing multi-threading.

  5. GUI:
    Design a graphical user interface for a more interactive user experience. This will allow visual representation of the ARP table, network dictionary, and the process flow.

  6. Time-To-Live (TTL) for ARP Table:
    Introduce a TTL for each entry in the ARP table. Once the TTL expires, the entry can be purged. This simulates the real-world scenario where ARP cache entries don't stay indefinitely.

  7. More Protocols:
    Extend the simulator to demonstrate other networking protocols such as ICMP (ping) or DHCP.

Conclusion

Understanding the ARP process is foundational in networking. This simulator provides a tangible, interactive method to visualize and experience the ARP resolution process. By enhancing and extending its functionalities, one can create a robust networking tool beneficial for both learning and simulation purposes.

About

This Python-based ARP Simulator implements a client-server model to demonstrate the Address Resolution Protocol (ARP) in a local network environment. Using a predefined network dictionary with IP and MAC address pairs, the server responds to MAC address queries while the client sends requests and updates its ARP table.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages