-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDHCP_Protocol_Analyzer.py
More file actions
126 lines (108 loc) · 4.53 KB
/
Copy pathDHCP_Protocol_Analyzer.py
File metadata and controls
126 lines (108 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* File: DHCP_Protocol_Analyzer.py
* Author: Amey Thakur
* GitHub: [Amey-Thakur](https://github.com/Amey-Thakur)
* Repository: [COMPUTER-NETWORKS](https://github.com/Amey-Thakur/COMPUTER-NETWORKS)
* Session: Fall 2023
* Release Date: November 01, 2023
* License: Creative Commons Attribution 4.0 International (CC BY 4.0)
*
* Description:
* Implements an analysis of the Dynamic Host Configuration Protocol (DHCP)
* allocation sequence. This module explores the DORA handshake (Discover,
* Offer, Request, ACK), UDP-based transport layers, and the function
* of the 32-bit transaction identifier (XID) during IP address assignment.
*/
import random
class DHCPSystemArchive:
"""
A collection of utilities to illustrate DHCP allocation and protocol mechanics.
"""
def __init__(self):
# Infrastructure configuration for DHCP simulation
self.server_ip = "192.168.2.1"
self.client_mac = "1c:4d:70:a6:0b:49"
self.lease_time = 259200 # 3 days in seconds
self.ports = {"Server": 67, "Client": 68}
def simulate_dora_process(self):
"""
Replicates the state transitions in a DHCP allocation handshake.
"""
transaction_id = "0x74292a0" # Constant for a single transaction set
print("\n" + "="*70)
print(f"SIMULATING DHCP DORA PROCESS (TRANS-ID: {transaction_id})")
print("="*70)
# 1. DISCOVER
print(f"[STAGE 1: DISCOVER] Client ({self.client_mac}) -> 255.255.255.255")
print(f" - IP: 0.0.0.0 -> 255.255.255.255 | UDP Port: {self.ports['Client']}->{self.ports['Server']}")
print(f" - Option 53: 1 (Discover)")
# 2. OFFER
offered_ip = "192.168.2.95"
print(f"\n[STAGE 2: OFFER] Server ({self.server_ip}) -> 255.255.255.255")
print(f" - IP: {self.server_ip} -> 255.255.255.255")
print(f" - Offered Address: {offered_ip} | Lease: {self.lease_time}s")
# 3. REQUEST
print(f"\n[STAGE 3: REQUEST] Client -> 255.255.255.255")
print(f" - Requesting IP: {offered_ip}")
print(f" - Option 53: 3 (Request)")
# 4. ACK
print(f"\n[STAGE 4: ACK] Server -> 255.255.255.255")
print(f" - Acknowledging Allocation of {offered_ip}")
print("="*70)
@staticmethod
def explain_transaction_id():
"""
Technical analysis of the 32-bit Transaction Identifier (XID).
"""
print("\n" + "-"*60)
print("TECHNICAL INSIGHT: THE TRANSACTION ID (XID)")
print("-"*60)
print("The Transaction ID is a unique 32-bit identifier generated by")
print("the client. It is used to match DHCP requests with server")
print("responses, ensuring that even in complex network environments,")
print("the client correctly identifies messages intended for its")
print("specific allocation handshake.")
print("-"*60)
@staticmethod
def display_scholarly_responses():
"""
Summarizes protocol identification results and allocation parameters.
"""
print("\n" + "="*75)
print("LABORATORY RESULTS: SCHOLARLY RESPONSES")
print("="*75)
responses = {
"Q1: Transport Protocol": "UDP (Ports 67, 68)",
"Q2: Transaction ID (XID)": "0x74292ax",
"Q5: DHCP Server IP": "192.168.2.1",
"Q6: Offered Client IP": "192.168.2.95",
"Q7: Lease Time": "259200s (3 Days)"
}
for q, a in responses.items():
print(f"{q:<30} : {a}")
print("="*75)
def main():
print("="*70)
print("SCHOLARLY ANALYSIS: DYNAMIC HOST CONFIGURATION PROTOCOL (DHCP)")
print("="*70)
archive = DHCPSystemArchive()
# 0. Scholarly Responses
analyzer = DHCPSystemArchive()
analyzer.display_scholarly_responses()
# 1. Execute the DORA simulation
archive.simulate_dora_process()
# 2. Provide protocol insights
archive.explain_transaction_id()
# 3. Scholarly Insight
print("\n" + "="*70)
print("SCHOLARLY INSIGHT & NETWORKING TIP")
print("="*70)
print("DHCP operates over UDP because at the start of the process, the")
print("client does not yet have an IP address to establish a TCP session.")
print("By using broadcast addresses and simple UDP datagrams, the client")
print("can discover local servers without prior configuration. This")
print("'Zero Configuration' capability is fundamental to the scalability")
print("of modern IP networks.")
print("="*70)
if __name__ == "__main__":
main()