or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.md

index.mddocs/

0

# ipaddress

1

2

Type stubs for Python's built-in ipaddress module, providing comprehensive type annotations for IP address and network manipulation operations. These stubs enable static type checking for IPv4 and IPv6 address operations, network calculations, and various IP address utilities.

3

4

## Package Information

5

6

- **Package Name**: types-ipaddress

7

- **Package Type**: Type stubs (PyPI)

8

- **Language**: Python

9

- **Installation**: `pip install types-ipaddress`

10

11

## Core Imports

12

13

```python

14

import ipaddress

15

import sys

16

from typing_extensions import Self

17

```

18

19

Common imports for specific functionality:

20

21

```python

22

from ipaddress import (

23

ip_address, ip_network, ip_interface,

24

IPv4Address, IPv6Address,

25

IPv4Network, IPv6Network,

26

IPv4Interface, IPv6Interface,

27

AddressValueError, NetmaskValueError

28

)

29

```

30

31

## Basic Usage

32

33

```python

34

import ipaddress

35

36

# Create IP addresses

37

ipv4_addr = ipaddress.ip_address('192.168.1.1')

38

ipv6_addr = ipaddress.ip_address('2001:db8::1')

39

40

# Create networks

41

network = ipaddress.ip_network('192.168.1.0/24')

42

print(f"Network: {network}")

43

print(f"Broadcast: {network.broadcast_address}")

44

print(f"Hosts: {list(network.hosts())[:5]}") # First 5 hosts

45

46

# Check if address is in network

47

if ipv4_addr in network:

48

print(f"{ipv4_addr} is in {network}")

49

50

# Create interfaces (address with network info)

51

interface = ipaddress.ip_interface('192.168.1.100/24')

52

print(f"Interface IP: {interface.ip}")

53

print(f"Interface Network: {interface.network}")

54

```

55

56

## Capabilities

57

58

### Factory Functions

59

60

Primary functions for creating IP address, network, and interface objects from various input types.

61

62

```python { .api }

63

def ip_address(address: int | str | bytes | IPv4Address | IPv6Address) -> IPv4Address | IPv6Address:

64

"""

65

Create an IP address object from a string, integer, or bytes.

66

67

Args:

68

address: IP address in various formats

69

70

Returns:

71

IPv4Address or IPv6Address object

72

73

Raises:

74

AddressValueError: If address format is invalid

75

"""

76

77

def ip_network(

78

address: int | str | bytes | IPv4Address | IPv6Address | IPv4Network | IPv6Network | IPv4Interface | IPv6Interface | tuple[int | str | bytes | IPv4Address | IPv6Address] | tuple[int | str | bytes | IPv4Address | IPv6Address, int],

79

strict: bool = True

80

) -> IPv4Network | IPv6Network:

81

"""

82

Create a network object from address/netmask or CIDR notation.

83

84

Args:

85

address: Network address in various formats, can include netmask

86

strict: If False, accept host bits set in network address

87

88

Returns:

89

IPv4Network or IPv6Network object

90

91

Raises:

92

AddressValueError: If network format is invalid

93

NetmaskValueError: If netmask is invalid

94

"""

95

96

def ip_interface(

97

address: int | str | bytes | IPv4Address | IPv6Address | IPv4Network | IPv6Network | IPv4Interface | IPv6Interface | tuple[int | str | bytes | IPv4Address | IPv6Address] | tuple[int | str | bytes | IPv4Address | IPv6Address, int]

98

) -> IPv4Interface | IPv6Interface:

99

"""

100

Create an interface object representing an address on a network.

101

102

Args:

103

address: Interface address in various formats, can include netmask

104

105

Returns:

106

IPv4Interface or IPv6Interface object

107

108

Raises:

109

AddressValueError: If address format is invalid

110

NetmaskValueError: If netmask is invalid

111

"""

112

```

113

114

### IPv4 Address Operations

115

116

Operations specific to IPv4 addresses with 32-bit addressing.

117

118

```python { .api }

119

class IPv4Address:

120

"""

121

IPv4 address representation with validation and utility methods.

122

"""

123

124

def __init__(self, address: object) -> None:

125

"""

126

Create IPv4 address from string, integer, or bytes.

127

128

Args:

129

address: IPv4 address representation

130

131

Raises:

132

AddressValueError: If address is invalid

133

"""

134

135

def __add__(self, other: int) -> IPv4Address:

136

"""Add integer to address."""

137

138

def __sub__(self, other: int) -> IPv4Address:

139

"""Subtract integer from address."""

140

141

def __int__(self) -> int:

142

"""Convert to integer representation."""

143

144

def __format__(self, fmt: str) -> str:

145

"""Format address as string."""

146

147

def __eq__(self, other: object) -> bool:

148

"""Check equality with another address."""

149

150

def __lt__(self, other: Self) -> bool:

151

"""Compare addresses (less than)."""

152

153

if sys.version_info >= (3, 11):

154

def __ge__(self, other: Self) -> bool:

155

"""Compare addresses (greater than or equal)."""

156

157

def __gt__(self, other: Self) -> bool:

158

"""Compare addresses (greater than)."""

159

160

def __le__(self, other: Self) -> bool:

161

"""Compare addresses (less than or equal)."""

162

else:

163

def __ge__(self, other: Self, NotImplemented: Any = ...) -> bool:

164

"""Compare addresses (greater than or equal)."""

165

166

def __gt__(self, other: Self, NotImplemented: Any = ...) -> bool:

167

"""Compare addresses (greater than)."""

168

169

def __le__(self, other: Self, NotImplemented: Any = ...) -> bool:

170

"""Compare addresses (less than or equal)."""

171

172

def __hash__(self) -> int:

173

"""Hash function for use in sets/dicts."""

174

175

@property

176

def compressed(self) -> str:

177

"""Compressed string representation."""

178

179

@property

180

def exploded(self) -> str:

181

"""Exploded string representation."""

182

183

@property

184

def packed(self) -> bytes:

185

"""Packed binary representation."""

186

187

@property

188

def reverse_pointer(self) -> str:

189

"""Reverse DNS pointer domain."""

190

191

if sys.version_info >= (3, 14):

192

version: Final = 4

193

max_prefixlen: Final = 32

194

else:

195

@property

196

def version(self) -> Literal[4]:

197

"""IP version (4)."""

198

199

@property

200

def max_prefixlen(self) -> Literal[32]:

201

"""Maximum prefix length (32)."""

202

203

@property

204

def is_global(self) -> bool:

205

"""True if address is global."""

206

207

@property

208

def is_link_local(self) -> bool:

209

"""True if address is link-local."""

210

211

@property

212

def is_loopback(self) -> bool:

213

"""True if address is loopback."""

214

215

@property

216

def is_multicast(self) -> bool:

217

"""True if address is multicast."""

218

219

@property

220

def is_private(self) -> bool:

221

"""True if address is private."""

222

223

@property

224

def is_reserved(self) -> bool:

225

"""True if address is reserved."""

226

227

@property

228

def is_unspecified(self) -> bool:

229

"""True if address is unspecified (0.0.0.0)."""

230

231

if sys.version_info >= (3, 13):

232

@property

233

def ipv6_mapped(self) -> IPv6Address:

234

"""Convert to IPv6-mapped address."""

235

```

236

237

### IPv6 Address Operations

238

239

Operations specific to IPv6 addresses with 128-bit addressing and additional IPv6-specific features.

240

241

```python { .api }

242

class IPv6Address:

243

"""

244

IPv6 address representation with validation and utility methods.

245

"""

246

247

def __init__(self, address: object) -> None:

248

"""

249

Create IPv6 address from string, integer, or bytes.

250

251

Args:

252

address: IPv6 address representation

253

254

Raises:

255

AddressValueError: If address is invalid

256

"""

257

258

def __add__(self, other: int) -> IPv6Address:

259

"""Add integer to address."""

260

261

def __sub__(self, other: int) -> IPv6Address:

262

"""Subtract integer from address."""

263

264

def __int__(self) -> int:

265

"""Convert to integer representation."""

266

267

def __format__(self, fmt: str) -> str:

268

"""Format address as string."""

269

270

def __eq__(self, other: object) -> bool:

271

"""Check equality with another address."""

272

273

def __lt__(self, other: Self) -> bool:

274

"""Compare addresses (less than)."""

275

276

if sys.version_info >= (3, 11):

277

def __ge__(self, other: Self) -> bool:

278

"""Compare addresses (greater than or equal)."""

279

280

def __gt__(self, other: Self) -> bool:

281

"""Compare addresses (greater than)."""

282

283

def __le__(self, other: Self) -> bool:

284

"""Compare addresses (less than or equal)."""

285

else:

286

def __ge__(self, other: Self, NotImplemented: Any = ...) -> bool:

287

"""Compare addresses (greater than or equal)."""

288

289

def __gt__(self, other: Self, NotImplemented: Any = ...) -> bool:

290

"""Compare addresses (greater than)."""

291

292

def __le__(self, other: Self, NotImplemented: Any = ...) -> bool:

293

"""Compare addresses (less than or equal)."""

294

295

def __hash__(self) -> int:

296

"""Hash function for use in sets/dicts."""

297

298

@property

299

def compressed(self) -> str:

300

"""Compressed string representation."""

301

302

@property

303

def exploded(self) -> str:

304

"""Exploded string representation."""

305

306

@property

307

def packed(self) -> bytes:

308

"""Packed binary representation."""

309

310

@property

311

def reverse_pointer(self) -> str:

312

"""Reverse DNS pointer domain."""

313

314

if sys.version_info >= (3, 14):

315

version: Final = 6

316

max_prefixlen: Final = 128

317

else:

318

@property

319

def version(self) -> Literal[6]:

320

"""IP version (6)."""

321

322

@property

323

def max_prefixlen(self) -> Literal[128]:

324

"""Maximum prefix length (128)."""

325

326

@property

327

def is_global(self) -> bool:

328

"""True if address is global."""

329

330

@property

331

def is_link_local(self) -> bool:

332

"""True if address is link-local."""

333

334

@property

335

def is_loopback(self) -> bool:

336

"""True if address is loopback."""

337

338

@property

339

def is_multicast(self) -> bool:

340

"""True if address is multicast."""

341

342

@property

343

def is_private(self) -> bool:

344

"""True if address is private."""

345

346

@property

347

def is_reserved(self) -> bool:

348

"""True if address is reserved."""

349

350

@property

351

def is_unspecified(self) -> bool:

352

"""True if address is unspecified (::)."""

353

354

@property

355

def is_site_local(self) -> bool:

356

"""True if address is site-local."""

357

358

@property

359

def ipv4_mapped(self) -> IPv4Address | None:

360

"""Extract IPv4 address if this is IPv4-mapped."""

361

362

@property

363

def sixtofour(self) -> IPv4Address | None:

364

"""Extract IPv4 address if this is 6to4."""

365

366

@property

367

def teredo(self) -> tuple[IPv4Address, IPv4Address] | None:

368

"""Extract Teredo server and client addresses."""

369

370

@property

371

def scope_id(self) -> str | None:

372

"""IPv6 scope identifier."""

373

```

374

375

### Network Operations

376

377

Operations for working with IP networks, including subnet calculations and network analysis.

378

379

```python { .api }

380

class IPv4Network:

381

"""

382

IPv4 network representation with subnet and host operations.

383

"""

384

385

def __init__(self, address: object, strict: bool = True) -> None:

386

"""

387

Create IPv4 network from CIDR or address/netmask.

388

389

Args:

390

address: Network specification

391

strict: If False, accept host bits in network address

392

393

Raises:

394

AddressValueError: If network address is invalid

395

NetmaskValueError: If netmask is invalid

396

"""

397

398

def __contains__(self, other: object) -> bool:

399

"""Check if address/network is contained in this network."""

400

401

def __getitem__(self, n: int) -> IPv4Address:

402

"""Get nth address in network."""

403

404

def __iter__(self) -> Iterator[IPv4Address]:

405

"""Iterate over all addresses in network."""

406

407

def __eq__(self, other: object) -> bool:

408

"""Check network equality."""

409

410

def __hash__(self) -> int:

411

"""Hash function for use in sets/dicts."""

412

413

def __lt__(self, other: Self) -> bool:

414

"""Compare networks (less than)."""

415

416

if sys.version_info >= (3, 11):

417

def __ge__(self, other: Self) -> bool:

418

"""Compare networks (greater than or equal)."""

419

420

def __gt__(self, other: Self) -> bool:

421

"""Compare networks (greater than)."""

422

423

def __le__(self, other: Self) -> bool:

424

"""Compare networks (less than or equal)."""

425

else:

426

def __ge__(self, other: Self, NotImplemented: Any = ...) -> bool:

427

"""Compare networks (greater than or equal)."""

428

429

def __gt__(self, other: Self, NotImplemented: Any = ...) -> bool:

430

"""Compare networks (greater than)."""

431

432

def __le__(self, other: Self, NotImplemented: Any = ...) -> bool:

433

"""Compare networks (less than or equal)."""

434

435

@property

436

def network_address(self) -> IPv4Address:

437

"""First address in network."""

438

439

@property

440

def broadcast_address(self) -> IPv4Address:

441

"""Last address in network."""

442

443

@property

444

def netmask(self) -> IPv4Address:

445

"""Network mask."""

446

447

@property

448

def hostmask(self) -> IPv4Address:

449

"""Host mask (inverse of netmask)."""

450

451

@property

452

def num_addresses(self) -> int:

453

"""Total number of addresses in network."""

454

455

@property

456

def prefixlen(self) -> int:

457

"""Network prefix length."""

458

459

@property

460

def with_prefixlen(self) -> str:

461

"""Network as CIDR string."""

462

463

@property

464

def with_netmask(self) -> str:

465

"""Network with explicit netmask."""

466

467

@property

468

def with_hostmask(self) -> str:

469

"""Network with explicit hostmask."""

470

471

@property

472

def is_global(self) -> bool:

473

"""True if network is global."""

474

475

@property

476

def is_link_local(self) -> bool:

477

"""True if network is link-local."""

478

479

@property

480

def is_loopback(self) -> bool:

481

"""True if network is loopback."""

482

483

@property

484

def is_multicast(self) -> bool:

485

"""True if network is multicast."""

486

487

@property

488

def is_private(self) -> bool:

489

"""True if network is private."""

490

491

@property

492

def is_reserved(self) -> bool:

493

"""True if network is reserved."""

494

495

@property

496

def is_unspecified(self) -> bool:

497

"""True if network is unspecified."""

498

499

def hosts(self) -> Iterator[IPv4Address] | list[IPv4Address]:

500

"""Iterate over usable host addresses (returns Iterator or list depending on network size)."""

501

502

def subnets(self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> Iterator[IPv4Network]:

503

"""Generate subnets of this network."""

504

505

def supernet(self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> IPv4Network:

506

"""Generate supernet containing this network."""

507

508

def subnet_of(self, other: IPv4Network) -> bool:

509

"""Check if this network is a subnet of another."""

510

511

def supernet_of(self, other: IPv4Network) -> bool:

512

"""Check if this network is a supernet of another."""

513

514

def overlaps(self, other: IPv4Network | IPv6Network) -> bool:

515

"""Check if networks overlap."""

516

517

def address_exclude(self, other: IPv4Network) -> Iterator[IPv4Network]:

518

"""Generate networks that exclude the other network."""

519

520

def compare_networks(self, other: IPv4Network) -> int:

521

"""Compare networks returning -1, 0, or 1."""

522

523

class IPv6Network:

524

"""

525

IPv6 network representation with subnet and host operations.

526

"""

527

528

def __init__(self, address: object, strict: bool = True) -> None:

529

"""

530

Create IPv6 network from CIDR or address/netmask.

531

532

Args:

533

address: Network specification

534

strict: If False, accept host bits in network address

535

536

Raises:

537

AddressValueError: If network address is invalid

538

NetmaskValueError: If netmask is invalid

539

"""

540

541

def __contains__(self, other: object) -> bool:

542

"""Check if address/network is contained in this network."""

543

544

def __getitem__(self, n: int) -> IPv6Address:

545

"""Get nth address in network."""

546

547

def __iter__(self) -> Iterator[IPv6Address]:

548

"""Iterate over all addresses in network."""

549

550

def __eq__(self, other: object) -> bool:

551

"""Check network equality."""

552

553

def __hash__(self) -> int:

554

"""Hash function for use in sets/dicts."""

555

556

def __lt__(self, other: Self) -> bool:

557

"""Compare networks (less than)."""

558

559

if sys.version_info >= (3, 11):

560

def __ge__(self, other: Self) -> bool:

561

"""Compare networks (greater than or equal)."""

562

563

def __gt__(self, other: Self) -> bool:

564

"""Compare networks (greater than)."""

565

566

def __le__(self, other: Self) -> bool:

567

"""Compare networks (less than or equal)."""

568

else:

569

def __ge__(self, other: Self, NotImplemented: Any = ...) -> bool:

570

"""Compare networks (greater than or equal)."""

571

572

def __gt__(self, other: Self, NotImplemented: Any = ...) -> bool:

573

"""Compare networks (greater than)."""

574

575

def __le__(self, other: Self, NotImplemented: Any = ...) -> bool:

576

"""Compare networks (less than or equal)."""

577

578

@property

579

def network_address(self) -> IPv6Address:

580

"""First address in network."""

581

582

@property

583

def broadcast_address(self) -> IPv6Address:

584

"""Last address in network."""

585

586

@property

587

def netmask(self) -> IPv6Address:

588

"""Network mask."""

589

590

@property

591

def hostmask(self) -> IPv6Address:

592

"""Host mask (inverse of netmask)."""

593

594

@property

595

def num_addresses(self) -> int:

596

"""Total number of addresses in network."""

597

598

@property

599

def prefixlen(self) -> int:

600

"""Network prefix length."""

601

602

@property

603

def with_prefixlen(self) -> str:

604

"""Network as CIDR string."""

605

606

@property

607

def with_netmask(self) -> str:

608

"""Network with explicit netmask."""

609

610

@property

611

def with_hostmask(self) -> str:

612

"""Network with explicit hostmask."""

613

614

@property

615

def is_global(self) -> bool:

616

"""True if network is global."""

617

618

@property

619

def is_link_local(self) -> bool:

620

"""True if network is link-local."""

621

622

@property

623

def is_loopback(self) -> bool:

624

"""True if network is loopback."""

625

626

@property

627

def is_multicast(self) -> bool:

628

"""True if network is multicast."""

629

630

@property

631

def is_private(self) -> bool:

632

"""True if network is private."""

633

634

@property

635

def is_reserved(self) -> bool:

636

"""True if network is reserved."""

637

638

@property

639

def is_unspecified(self) -> bool:

640

"""True if network is unspecified."""

641

642

@property

643

def is_site_local(self) -> bool:

644

"""True if network is site-local."""

645

646

def hosts(self) -> Iterator[IPv6Address] | list[IPv6Address]:

647

"""Iterate over usable host addresses (returns Iterator or list depending on network size)."""

648

649

def subnets(self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> Iterator[IPv6Network]:

650

"""Generate subnets of this network."""

651

652

def supernet(self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> IPv6Network:

653

"""Generate supernet containing this network."""

654

655

def subnet_of(self, other: IPv6Network) -> bool:

656

"""Check if this network is a subnet of another."""

657

658

def supernet_of(self, other: IPv6Network) -> bool:

659

"""Check if this network is a supernet of another."""

660

661

def overlaps(self, other: IPv4Network | IPv6Network) -> bool:

662

"""Check if networks overlap."""

663

664

def address_exclude(self, other: IPv6Network) -> Iterator[IPv6Network]:

665

"""Generate networks that exclude the other network."""

666

667

def compare_networks(self, other: IPv6Network) -> int:

668

"""Compare networks returning -1, 0, or 1."""

669

```

670

671

### Interface Operations

672

673

Operations for IP interfaces, which combine an address with its associated network information.

674

675

```python { .api }

676

class IPv4Interface(IPv4Address):

677

"""

678

IPv4 interface representing an address on a network.

679

"""

680

681

# Direct attributes (not properties)

682

netmask: IPv4Address

683

network: IPv4Network

684

685

def __eq__(self, other: object) -> bool:

686

"""Check equality with another interface."""

687

688

def __hash__(self) -> int:

689

"""Hash function for use in sets/dicts."""

690

691

@property

692

def ip(self) -> IPv4Address:

693

"""The address portion of the interface."""

694

695

@property

696

def hostmask(self) -> IPv4Address:

697

"""Host mask of the interface."""

698

699

@property

700

def with_prefixlen(self) -> str:

701

"""Interface as CIDR string."""

702

703

@property

704

def with_netmask(self) -> str:

705

"""Interface with explicit netmask."""

706

707

@property

708

def with_hostmask(self) -> str:

709

"""Interface with explicit hostmask."""

710

711

class IPv6Interface(IPv6Address):

712

"""

713

IPv6 interface representing an address on a network.

714

"""

715

716

# Direct attributes (not properties)

717

netmask: IPv6Address

718

network: IPv6Network

719

720

def __eq__(self, other: object) -> bool:

721

"""Check equality with another interface."""

722

723

def __hash__(self) -> int:

724

"""Hash function for use in sets/dicts."""

725

726

@property

727

def ip(self) -> IPv6Address:

728

"""The address portion of the interface."""

729

730

@property

731

def hostmask(self) -> IPv6Address:

732

"""Host mask of the interface."""

733

734

@property

735

def with_prefixlen(self) -> str:

736

"""Interface as CIDR string."""

737

738

@property

739

def with_netmask(self) -> str:

740

"""Interface with explicit netmask."""

741

742

@property

743

def with_hostmask(self) -> str:

744

"""Interface with explicit hostmask."""

745

```

746

747

### Utility Functions

748

749

Helper functions for address conversion, network summarization, and mixed-type operations.

750

751

```python { .api }

752

def v4_int_to_packed(address: int) -> bytes:

753

"""

754

Convert IPv4 integer to 4-byte packed representation.

755

756

Args:

757

address: IPv4 address as integer

758

759

Returns:

760

4-byte packed representation

761

"""

762

763

def v6_int_to_packed(address: int) -> bytes:

764

"""

765

Convert IPv6 integer to 16-byte packed representation.

766

767

Args:

768

address: IPv6 address as integer

769

770

Returns:

771

16-byte packed representation

772

"""

773

774

# Overloaded function with multiple signatures

775

def summarize_address_range(first: IPv4Address, last: IPv4Address) -> Iterator[IPv4Network]: ...

776

def summarize_address_range(first: IPv6Address, last: IPv6Address) -> Iterator[IPv6Network]: ...

777

def summarize_address_range(

778

first: IPv4Address | IPv6Address,

779

last: IPv4Address | IPv6Address

780

) -> Iterator[IPv4Network] | Iterator[IPv6Network]:

781

"""

782

Summarize a range of addresses into the minimal set of networks.

783

784

Args:

785

first: First address in range

786

last: Last address in range

787

788

Returns:

789

Iterator of networks covering the range

790

791

Raises:

792

TypeError: If addresses are different versions

793

ValueError: If first > last

794

"""

795

796

def collapse_addresses(addresses: Iterable[_N]) -> Iterator[_N]:

797

"""

798

Collapse overlapping and adjacent networks.

799

800

Args:

801

addresses: Iterable of network objects (IPv4Network or IPv6Network)

802

803

Returns:

804

Iterator of collapsed networks of the same type

805

"""

806

807

# Overloaded function with multiple signatures

808

def get_mixed_type_key(obj: IPv4Address | IPv6Address) -> tuple[int, IPv4Address | IPv6Address]: ...

809

def get_mixed_type_key(obj: IPv4Network) -> tuple[int, IPv4Address, IPv4Address]: ...

810

def get_mixed_type_key(obj: IPv6Network) -> tuple[int, IPv6Address, IPv6Address]: ...

811

def get_mixed_type_key(

812

obj: IPv4Address | IPv6Address | IPv4Network | IPv6Network

813

) -> tuple[int, IPv4Address | IPv6Address] | tuple[int, IPv4Address, IPv4Address] | tuple[int, IPv6Address, IPv6Address]:

814

"""

815

Generate sorting key for mixed IPv4/IPv6 objects.

816

817

Args:

818

obj: Address or network object

819

820

Returns:

821

Tuple for sorting mixed-type collections

822

"""

823

```

824

825

## Constants

826

827

```python { .api }

828

IPV4LENGTH: int = 32

829

"""Length of IPv4 addresses in bits."""

830

831

IPV6LENGTH: int = 128

832

"""Length of IPv6 addresses in bits."""

833

```

834

835

## Exceptions

836

837

```python { .api }

838

class AddressValueError(ValueError):

839

"""

840

Exception raised when an invalid IP address is provided.

841

"""

842

843

class NetmaskValueError(ValueError):

844

"""

845

Exception raised when an invalid netmask is provided.

846

"""

847

```

848

849

## Type Variables and Aliases

850

851

```python { .api }

852

import sys

853

from typing import Any, Final, Generic, Literal, TypeVar, overload

854

from typing_extensions import Self, TypeAlias

855

from collections.abc import Iterable, Iterator

856

857

# Type variables used throughout the module

858

_A = TypeVar("_A", IPv4Address, IPv6Address)

859

_N = TypeVar("_N", IPv4Network, IPv6Network)

860

861

# Type aliases for flexible input types

862

_RawIPAddress: TypeAlias = int | str | bytes | IPv4Address | IPv6Address

863

_RawNetworkPart: TypeAlias = IPv4Network | IPv6Network | IPv4Interface | IPv6Interface

864

```