API Reference
This section provides references for the primary classes in the pydhcp package.
DhcpMessage
pydhcp.packet.message.DhcpMessage
dataclass
Source code in src/pydhcp/packet/message.py
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
MAGIC_COOKIE = 1669485411.to_bytes(4, 'big')
class-attribute
The first four octets of the 'options' field of the DHCP message decimal values: 99, 130, 83 and 99
chaddr
instance-attribute
Client hardware address.
ciaddr
instance-attribute
Client IP address; only filled in if client is in BOUND, RENEW or REBINDING state and can respond to ARP requests.
file
instance-attribute
Boot file name, null terminated string; "generic" name or null in DHCPDISCOVER, fully qualified directory-path name in DHCPOFFER.
flags
instance-attribute
Only use for the BROADCAST flag in clients
giaddr
instance-attribute
Relay agent IP address, used in booting via a relay agent.
hlen
instance-attribute
Hardware address length
hops
instance-attribute
Client sets to zero, optionally used by relay agents when booting via a relay agent.
htype
instance-attribute
Hardware address type, see ARP section in "Assigned Numbers" RFC
op
instance-attribute
Message op code / message type
options
instance-attribute
Optional parameters field.
secs
instance-attribute
Filled in by client, seconds elapsed since client began address acquisition or renewal process.
siaddr
instance-attribute
IP address of next server to use in bootstrap; returned in DHCPOFFER, DHCPACK by server.
sname
instance-attribute
Optional server host name, null terminated string.
xid
instance-attribute
Transaction ID, a random number chosen by the client, used by the client and server to associate messages and responses between a client and a server.
yiaddr
instance-attribute
'your' (client) IP address.
DhcpOptions
pydhcp.options.DhcpOptions
Bases: MutableMapping[int, bytearray]
Source code in src/pydhcp/options/__init__.py
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
Option Types
pydhcp.options.type
Boolean
Bases: DhcpOptionType, int
Boolean option encoded as a single octet.
Source code in src/pydhcp/options/type/scalar.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
Bytes
Bases: DhcpOptionType, bytes
Opaque byte payload.
Source code in src/pydhcp/options/type/scalar.py
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 | |
CccApReqApRepBackoffRetry
Bases: CccAsReqAsRepBackoffRetry
CCC sub-option 5 AP-REQ/AP-REP backoff and retry tuple.
Source code in src/pydhcp/options/ccc.py
208 209 | |
CccAsReqAsRepBackoffRetry
Bases: DhcpOptionType
CCC sub-option 4 AS-REQ/AS-REP backoff and retry tuple.
Source code in src/pydhcp/options/ccc.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
CccKdcServerAddressList
Bases: List[IPv4Address]
CCC sub-option 10 KDC server address list.
Source code in src/pydhcp/options/ccc.py
247 248 | |
CccKerberosRealmName
Bases: _CccDomainText
CCC Kerberos realm payload without DNS compression.
Source code in src/pydhcp/options/ccc.py
70 71 72 73 74 | |
CccOption
Bases: DhcpOptionType, list[CccSubOption]
CCC option container preserving unknown sub-options.
Source code in src/pydhcp/options/ccc.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
CccPrimaryDhcpServerAddress
Bases: IPv4Address
CCC sub-option 1 primary DHCP server address.
Source code in src/pydhcp/options/ccc.py
149 150 | |
CccProvisioningServerAddress
Bases: DhcpOptionType
CCC sub-option 3 tagged union for IPv4 address or FQDN.
Source code in src/pydhcp/options/ccc.py
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
CccProvisioningServerFqdn
Bases: _CccDomainText
CCC provisioning server FQDN payload without DNS compression.
Source code in src/pydhcp/options/ccc.py
66 67 | |
CccProvisioningTimer
Bases: U8
CCC sub-option 8 provisioning timer value.
Source code in src/pydhcp/options/ccc.py
216 217 | |
CccSecondaryDhcpServerAddress
Bases: IPv4Address
CCC sub-option 2 secondary DHCP server address.
Source code in src/pydhcp/options/ccc.py
153 154 | |
CccSecurityTicketControl
Bases: DhcpOptionType, int
CCC sub-option 9 security ticket control mask.
Source code in src/pydhcp/options/ccc.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
CccSubOption
Bases: DhcpOptionType
Typed CCC sub-option record.
Source code in src/pydhcp/options/ccc.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
CccTicketGrantingServerUtilization
Bases: Boolean
CCC sub-option 7 ticket-granting server utilization toggle.
Source code in src/pydhcp/options/ccc.py
212 213 | |
ClasslessRoute
Bases: DhcpOptionType
RFC 3442 classless static route entry.
Source code in src/pydhcp/options/type/net.py
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 | |
ClientIdentifier
Bases: Bytes
RFC 2132 client identifier.
Source code in src/pydhcp/options/type/scalar.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
DhcpOptionCodes
Bases: List[_C]
List of option codes used by parameter-request-list style options.
Source code in src/pydhcp/options/type/base.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
DhcpOptionType
Protocol for DHCP option payload codecs.
Implementations decode with _dhcp_read, encode with _dhcp_write, and may
advertise a fixed size with _dhcp_len_hint. The encode/decode pair should
round-trip the same Python value.
Source code in src/pydhcp/options/type/base.py
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 | |
DomainList
Bases: DhcpOptionType, list[str]
RFC 1035 domain-name list with compression support.
Source code in src/pydhcp/options/type/net.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
I32
Bases: FixedLengthInteger
Signed 32-bit integer.
Source code in src/pydhcp/options/type/scalar.py
199 200 201 202 | |
IPv4Address
Bases: DhcpOptionType, IPv4
A single IPv4 address carried in network byte order.
Source code in src/pydhcp/options/type/net.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
List
Bases: DhcpOptionType, list[_T]
Typed DHCP option list container.
Source code in src/pydhcp/options/type/base.py
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 | |
MoSFqdnList
Bases: _MoSOptionBase
RFC 5678 MoS option carrying FQDN sub-options.
Source code in src/pydhcp/options/type/mos.py
268 269 270 271 | |
MoSFqdnRecord
Bases: _MoSFqdnSubOption
RFC 5678 MoS sub-option record carrying FQDN label sequences.
Source code in src/pydhcp/options/type/mos.py
214 215 | |
MoSIpv4AddressList
Bases: _MoSOptionBase
RFC 5678 MoS option carrying IPv4 address sub-options.
Source code in src/pydhcp/options/type/mos.py
262 263 264 265 | |
MoSIpv4AddressRecord
Bases: _MoSIpv4AddressSubOption
RFC 5678 MoS sub-option record carrying IPv4 addresses.
Source code in src/pydhcp/options/type/mos.py
210 211 | |
OptionOverload
Bases: DhcpOptionType, IntFlag
RFC 2132 option-overload selector.
Source code in src/pydhcp/options/type/scalar.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
PolicyFilter
Bases: _IPv4PairList
List of IPv4 destination/mask pairs for policy filtering.
Source code in src/pydhcp/options/type/net.py
119 120 | |
RdnssSelection
Bases: DhcpOptionType
RFC 6731 RDNSS selection payload.
Source code in src/pydhcp/options/type/net.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
RelayAgentInformation
Bases: EncapsulatedOptions
RFC 3046 relay-agent sub-options.
Source code in src/pydhcp/options/type/vendor.py
155 156 | |
StaticRoute
Bases: _IPv4PairList
List of IPv4 destination/router pairs for static routing.
Source code in src/pydhcp/options/type/net.py
123 124 125 126 127 128 129 130 131 | |
String
Bases: DhcpOptionType, str
RFC 2132 NVT-ASCII string with null termination on the wire.
Source code in src/pydhcp/options/type/scalar.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
U16
Bases: FixedLengthInteger
Unsigned 16-bit integer.
Source code in src/pydhcp/options/type/scalar.py
187 188 189 190 | |
U32
Bases: FixedLengthInteger
Unsigned 32-bit integer.
Source code in src/pydhcp/options/type/scalar.py
193 194 195 196 | |
U8
Bases: FixedLengthInteger
Unsigned 8-bit integer.
Source code in src/pydhcp/options/type/scalar.py
181 182 183 184 | |
UriList
Bases: DhcpOptionType, list[str]
List of UTF-8 URIs encoded as repeated U16-length-prefixed entries.
Source code in src/pydhcp/options/type/scalar.py
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 | |
UserClass
Bases: _LengthPrefixedOpaqueList
RFC 3004 user-class opaque byte list.
Source code in src/pydhcp/options/type/vendor.py
71 72 | |
VendorSpecificInformation
Bases: Bytes
Opaque vendor-specific payload for option 43.
Source code in src/pydhcp/options/type/vendor.py
151 152 | |
ViVendorClass
Bases: DhcpOptionType, list[ViVendorClassRecord]
RFC 3925 vendor-identifying vendor class records.
Source code in src/pydhcp/options/type/vendor.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
ViVendorSpecificInformation
Bases: DhcpOptionType, list[ViVendorSpecificInformationRecord]
RFC 3925 vendor-identifying vendor-specific information records.
Source code in src/pydhcp/options/type/vendor.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
DhcpServer
pydhcp.server.DhcpServer
Bases: DhcpListener
Source code in src/pydhcp/server.py
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
acquire_lease(client_id, server_id, msg)
Return a lease for a client message.
The base implementation is intentionally small: it renews existing leases and
allocates only when the client supplies REQUESTED_IP or ciaddr. Override
this method to implement address pools, reservations, policy checks, or custom
response options.
Source code in src/pydhcp/server.py
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 | |
get_inform_options(server_id, msg)
Return configuration options for DHCPINFORM responses.
DHCPINFORM does not allocate an address. Override this method when clients should receive site-specific options without touching lease allocation.
Source code in src/pydhcp/server.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
handle_decline(msg, context)
Handle DHCPDECLINE by releasing the client's lease through release_lease.
Source code in src/pydhcp/server.py
192 193 194 195 196 197 | |
handle_discover(msg, context)
Handle DHCPDISCOVER by offering a lease returned from acquire_lease.
Source code in src/pydhcp/server.py
155 156 157 158 159 160 161 162 163 164 165 166 167 | |
handle_inform(msg, context)
Handle DHCPINFORM without requiring address allocation.
Source code in src/pydhcp/server.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
handle_release(msg, context)
Handle DHCPRELEASE by releasing the client's lease through release_lease.
Source code in src/pydhcp/server.py
199 200 201 202 203 204 | |
handle_request(msg, context)
Handle DHCPREQUEST by ACKing or NAKing the lease returned from acquire_lease.
Source code in src/pydhcp/server.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
release_lease(client_id, server_id, msg)
Release any lease associated with client_id.
Override this method when lease release needs to update an external store, quarantine declined addresses, or emit custom audit records.
Source code in src/pydhcp/server.py
87 88 89 90 91 92 93 94 | |
DhcpClient
pydhcp.client.DhcpClient
Bases: DhcpListener
Small DHCPv4 packet client for tests and troubleshooting.
The base client builds and sends DHCP client messages, then queues matching replies. It does not configure operating-system network interfaces.
Source code in src/pydhcp/client.py
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
discover_offer(chaddr, *, timeout=2.0, retries=2, destination=_net.IPv4('255.255.255.255'), port=int(_enum.DhcpPort.SERVER), **discover_kwargs)
Broadcast DHCPDISCOVER and return the first DHCPOFFER, or None.
Source code in src/pydhcp/client.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
dora(chaddr, *, timeout=2.0, retries=2, destination=_net.IPv4('255.255.255.255'), port=int(_enum.DhcpPort.SERVER), broadcast=True, **discover_kwargs)
Run a full DISCOVER/OFFER/REQUEST/ACK exchange and return the DHCPACK, or None.
Source code in src/pydhcp/client.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
on_reply(msg, context)
Hook called after a BOOTREPLY is accepted and queued.
Source code in src/pydhcp/client.py
228 229 | |
DhcpRelay
pydhcp.relay.DhcpRelay
Bases: DhcpListener
RFC 1542 / RFC 2131 4.1 / RFC 3046 DHCP relay agent.
Forwards client broadcasts (received on port 67, same as a server) to one or
more configured upstream DHCP servers, stamping giaddr and incrementing
hops. Forwards server replies (unicast back to this relay) on to the
client, applying the same destination rules a server uses on its own
client-facing side (broadcast flag, else yiaddr/ciaddr).
Source code in src/pydhcp/relay.py
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 | |
DhcpCapture
pydhcp.capture.DhcpCapture
Bases: DhcpListener
Source code in src/pydhcp/capture.py
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 127 128 129 130 131 132 133 134 | |
CaptureEvent
pydhcp.capture.CaptureEvent
dataclass
Source code in src/pydhcp/capture.py
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 | |
AsyncDhcpServer
pydhcp.server.AsyncDhcpServer
Bases: AsyncDhcpListener, DhcpServer
Source code in src/pydhcp/server.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
DhcpListener
pydhcp.listener.DhcpListener
Source code in src/pydhcp/listener.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
AsyncDhcpListener
pydhcp.listener.AsyncDhcpListener
Source code in src/pydhcp/listener.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
DhcpMetrics
Every DhcpListener (and therefore DhcpServer, DhcpClient) owns its own metrics: DhcpMetrics
instance — counters are per-instance, not global, so running multiple listeners in one process
(e.g. in tests) never cross-contaminates counts. Call .snapshot() for a plain dict[str, int].
pydhcp.metrics.DhcpMetrics
Source code in src/pydhcp/metrics.py
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 | |
pydhcp.client
pydhcp.client
DhcpClient
Bases: DhcpListener
Small DHCPv4 packet client for tests and troubleshooting.
The base client builds and sends DHCP client messages, then queues matching replies. It does not configure operating-system network interfaces.
Source code in src/pydhcp/client.py
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
discover_offer(chaddr, *, timeout=2.0, retries=2, destination=_net.IPv4('255.255.255.255'), port=int(_enum.DhcpPort.SERVER), **discover_kwargs)
Broadcast DHCPDISCOVER and return the first DHCPOFFER, or None.
Source code in src/pydhcp/client.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
dora(chaddr, *, timeout=2.0, retries=2, destination=_net.IPv4('255.255.255.255'), port=int(_enum.DhcpPort.SERVER), broadcast=True, **discover_kwargs)
Run a full DISCOVER/OFFER/REQUEST/ACK exchange and return the DHCPACK, or None.
Source code in src/pydhcp/client.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
on_reply(msg, context)
Hook called after a BOOTREPLY is accepted and queued.
Source code in src/pydhcp/client.py
228 229 | |
pydhcp.capture
pydhcp.capture
pydhcp.packet
pydhcp.packet
DhcpMessage
dataclass
Source code in src/pydhcp/packet/message.py
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
MAGIC_COOKIE = 1669485411.to_bytes(4, 'big')
class-attribute
The first four octets of the 'options' field of the DHCP message decimal values: 99, 130, 83 and 99
chaddr
instance-attribute
Client hardware address.
ciaddr
instance-attribute
Client IP address; only filled in if client is in BOUND, RENEW or REBINDING state and can respond to ARP requests.
file
instance-attribute
Boot file name, null terminated string; "generic" name or null in DHCPDISCOVER, fully qualified directory-path name in DHCPOFFER.
flags
instance-attribute
Only use for the BROADCAST flag in clients
giaddr
instance-attribute
Relay agent IP address, used in booting via a relay agent.
hlen
instance-attribute
Hardware address length
hops
instance-attribute
Client sets to zero, optionally used by relay agents when booting via a relay agent.
htype
instance-attribute
Hardware address type, see ARP section in "Assigned Numbers" RFC
op
instance-attribute
Message op code / message type
options
instance-attribute
Optional parameters field.
secs
instance-attribute
Filled in by client, seconds elapsed since client began address acquisition or renewal process.
siaddr
instance-attribute
IP address of next server to use in bootstrap; returned in DHCPOFFER, DHCPACK by server.
sname
instance-attribute
Optional server host name, null terminated string.
xid
instance-attribute
Transaction ID, a random number chosen by the client, used by the client and server to associate messages and responses between a client and a server.
yiaddr
instance-attribute
'your' (client) IP address.
DhcpMessageType
Bases: DhcpOptionType, IntEnum
DHCP message types
Source code in src/pydhcp/packet/enums.py
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 | |
DHCPACK = 5
class-attribute
instance-attribute
Server to client with configuration parameters, including committed network address.
DHCPDECLINE = 4
class-attribute
instance-attribute
Client to server indicating network address is already in use.
DHCPDISCOVER = 1
class-attribute
instance-attribute
Client broadcast to locate available servers.
DHCPFORCERENEW = 9
class-attribute
instance-attribute
Forces the client to the RENEW state.
DHCPINFORM = 8
class-attribute
instance-attribute
Client to server, asking only for local configuration parameters; client already has externally configured network address.
DHCPLEASEACTIVE = 13
class-attribute
instance-attribute
The DHCPLEASEACTIVE response to a DHCPLEASEQUERY message allows the relay agent to determine the IP endpoint location and the remaining duration of the IP address lease.
DHCPLEASEQUERY = 10
class-attribute
instance-attribute
The DHCPLEASEQUERY message is a new DHCP message type transmitted from a DHCP relay agent to a DHCP server. A DHCPLEASEQUERY-aware relay agent sends the DHCPLEASEQUERY message when it needs to know the location of an IP endpoint. The DHCPLEASEQUERY-aware DHCP server replies with a DHCPLEASEUNASSIGNED, DHCPLEASEACTIVE, or DHCPLEASEUNKNOWN message.
DHCPLEASEUNASSIGNED = 11
class-attribute
instance-attribute
The DHCPLEASEUNASSIGNED is similar to a DHCPLEASEACTIVE message, but indicates that there is no currently active lease on the resultant IP address but that this DHCP server is authoritative for this IP address.
DHCPLEASEUNKNOWN = 12
class-attribute
instance-attribute
The DHCPLEASEUNKNOWN message indicates that the DHCP server has no knowledge of the information specified in the query (e.g., IP address, MAC address, or Client-identifier option).
DHCPNAK = 6
class-attribute
instance-attribute
Server to client indicating client's notion of network address is incorrect (e.g., client has moved to new subnet) or client's lease as expired
DHCPOFFER = 2
class-attribute
instance-attribute
Server to client in response to DHCPDISCOVER with offer of configuration parameters.
DHCPRELEASE = 7
class-attribute
instance-attribute
Client to server relinquishing network address and cancelling remaining lease.
DHCPREQUEST = 3
class-attribute
instance-attribute
Client message to servers either (a) requesting offered parameters from one server and implicitly declining offers from all others, (b) confirming correctness of previously allocated address after, e.g., system reboot, or (c) extending the lease on a particular network address.
Flags
Bases: Flag
Source code in src/pydhcp/packet/enums.py
115 116 117 118 | |
BROADCAST = 1 << 15
class-attribute
instance-attribute
Set by client that cant listen to unicast response as it doesnt have an ip yet
OpCode
Bases: IntEnum
Specifies if the message originates from a server or client
Source code in src/pydhcp/packet/enums.py
101 102 103 104 105 106 107 | |
BOOTREPLY = 2
class-attribute
instance-attribute
DHCP message sent from a server to a client.
BOOTREQUEST = 1
class-attribute
instance-attribute
DHCP message sent from a client to a server.
pydhcp.network
pydhcp.network
MACAddress
Bases: MACAddress
A hardware address rendered the way DHCP tooling expects.
Only the presentation differs from :class:netimps.MACAddress:
uppercase-hyphenated (00-11-22-33-44-55) rather than lowercase-colon,
because that is the form this project's CLI and logs have always used.
Parsing, comparison and hashing are inherited unchanged, so instances
compare equal to the base type and interoperate with it as dict keys.
Note this is a display type. The wire hardware address (chaddr,
option 61) is raw bytes throughout packet/ and never passes through
here -- deliberately, since chaddr permits hlen up to 16 for
non-Ethernet htype while a MAC is exactly 6.
Source code in src/pydhcp/network/__init__.py
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 | |
hex(*args, **kwargs)
bytes.hex passthrough.
The base type is a value object exposing .packed rather than a
bytes subclass, so this method is not inherited -- but callers
(and tests) predating that reasonably expect it.
Source code in src/pydhcp/network/__init__.py
38 39 40 41 42 43 44 45 | |
SocketAddress
Bases: _SocketAddress
Source code in src/pydhcp/network/__init__.py
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 | |
listen(family=_socket.AF_INET, kind=_socket.SOCK_DGRAM, proto=0, fileno=None, options=())
Create and bind a socket at this address.
options are (level, name, value) triples applied before the
bind. Delegates to :func:netimps.bind, which closes the socket before
any exception propagates -- so a failed bind leaks nothing.
reuse_address is left off: this has never set SO_REUSEADDR
implicitly, and turning it on now would let a socket bind a port still
in TIME_WAIT. Callers that want it pass it in options, as
listener.py does.
Source code in src/pydhcp/network/__init__.py
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 | |
host_ip_interfaces(filter=True, family=4)
Yield one :class:NetworkInterface per local address.
One entry per address, not per adapter, since callers here select and
filter by address. filter defaults to excluding APIPA; pass False
for everything, or a predicate of your own.
family defaults to 4: this is a DHCPv4 implementation, and the
enumeration it replaced was IPv4-only, so yielding IPv6 addresses would
silently change what existing callers iterate over. Pass None for both
families or 6 for IPv6 only.
Enumeration comes from :func:netimps.iter_addresses, which reports real
prefix lengths and human-readable adapter names on every platform.
Source code in src/pydhcp/network/__init__.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |