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.
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.
- 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.
- Python 3.x
- Clone this repository:
git clone [repository_link]
- Navigate to the project directory:
cd path_to_directory
- Start the ARP server:
python server.py
After running the command, you should see the message "ARP server is listening...".
- In a separate terminal, start the ARP client:
python client.py
You'll be prompted with "Enter IP to ARP for:".
- Enter any IP from the list (e.g.,
192.168.1.1
), and the client will display the associated MAC address.
The code provided above has two main segments: the ARP server and the ARP client.
-
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.
- It binds to a specific IP (
-
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.
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:
-
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. -
Socket Initialization:
The code initializes a socket using thesocket.AF_INET
address family (IPv4) and thesocket.SOCK_STREAM
socket type (TCP). -
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. -
Connection Handling:
Upon accepting a connection, the server retrieves the IP address sent by the client, searches theNETWORK
dictionary, and sends back the corresponding MAC address, or 'Not Found' if the IP isn't present in the dictionary.
Purpose: The client simulates a device in the network that wishes to resolve an IP address to a MAC address.
Key Components:
-
ARP Table (
ARP_TABLE
):
This is the client's ARP cache. Initially empty, it gets populated as the client resolves IP addresses. -
User Input:
The client prompts the user for an IP address that it wants to resolve. -
Socket Communication:
The client uses a socket to send the input IP to the server and awaits a response. -
Table Update:
Based on the server's response, the client updates its ARP table.
-
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. -
Error Handling:
Implement error handling to manage scenarios such as server unavailability, incorrect IP format, etc. -
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. -
Multi-threading:
Allow the server to handle multiple client requests simultaneously by implementing multi-threading. -
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. -
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. -
More Protocols:
Extend the simulator to demonstrate other networking protocols such as ICMP (ping) or DHCP.
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.