Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To generate a random IPv4 address by legacy class, choose a class, then select an address whose first bits match that class: A uses 0, B 10, C 110, D 1110, and E 1111. The Python generator below does that and can optionally filter out several special-purpose ranges. Treat its output as a sample—not proof that an address is public, reachable, unassigned, or appropriate for your network. Modern IPv4 allocation and routing use CIDR prefixes, not the old A/B/C class system. RFC 4632 and the IANA IPv4 Special-Purpose Address Registry explain the distinction.
What “generate an IPv4 address by class” means
IPv4 addresses are 32-bit numbers, usually written as four decimal octets separated by dots—for example, 203.0.113.10. Historically, the first bits of an address identified a class, and A, B, and C used different default divisions between network and host bits. A class-oriented random IP generator can select values matching those historic leading-bit patterns.
That is a useful learning exercise, but it is not how you should choose an address block for a real network. Classful assignment was deprecated in favor of classless, hierarchical prefixes. A CIDR prefix such as /24 says that the first 24 bits identify the block; it does not mean the block is automatically “Class C.” See RFC 4632.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →IPv4 address classes at a glance
| Legacy class | Leading bits | First-octet range | Historical role | What to watch for |
|---|---|---|---|---|
| A | 0 |
1–126 for ordinary legacy networks | Large unicast network blocks | The broader bit pattern includes special cases: the zero network and 127.0.0.0/8 loopback are not ordinary public host space. |
| B | 10 |
128–191 | Medium-sized unicast blocks | Private-use space 172.16.0.0/12 falls within this numeric span. |
| C | 110 |
192–223 | Smaller unicast blocks | The span contains many special-purpose values; do not treat it all as public address space. |
| D | 1110 |
224–239 | Multicast | These are not ordinary unicast host addresses. |
| E | 1111 |
240–255 | Reserved / future use | 255.255.255.255 is limited broadcast, not a normal host address. |
RFC 4632 documents the historical A/B/C leading-bit patterns and the transition away from class-based assignment. The IANA address-space registry identifies the Class D and Class E names and ranges; consult the live IANA IPv4 Address Space registry for those labels. “Class” describes a legacy categorization, not a guarantee about current use, reachability, or assignment.
#1 Best Overall
Generate sample addresses with Python
This script takes a class and a count, generates random IPv4 values matching the legacy first-octet range, and prints them. By default it accepts any value in that class range. Add --exclude-listed-special to reject the private, loopback, link-local, documentation, multicast, reserved, and limited-broadcast ranges listed in the code.
#!/usr/bin/env python3
import argparse
import ipaddress
import secrets
# Legacy first-octet ranges for the class-oriented exercise.
RANGES = {
"A": (1, 126),
"B": (128, 191),
"C": (192, 223),
"D": (224, 239),
"E": (240, 255),
}
# Deliberately explicit examples of special-use ranges to exclude.
# This list is not a complete substitute for the current IANA registry.
EXCLUDED = tuple(ipaddress.ip_network(cidr) for cidr in (
"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16",
"0.0.0.0/8", "127.0.0.0/8", "169.254.0.0/16",
"192.0.2.0/24", "198.51.100.0/24", "203.0.113.0/24",
"224.0.0.0/4", "240.0.0.0/4", "255.255.255.255/32",
))
def generate(class_name, count, exclude_special=False):
low, high = RANGES[class_name]
results = []
while len(results) < count:
address = ipaddress.IPv4Address(
(secrets.randbelow(high - low + 1) + low) << 24
| secrets.randbits(24)
)
if exclude_special and any(address in network for network in EXCLUDED):
continue
results.append(address)
return results
parser = argparse.ArgumentParser(description="Generate legacy class-based IPv4 samples")
parser.add_argument("class_name", choices=RANGES)
parser.add_argument("-n", "--count", type=int, default=10)
parser.add_argument("--exclude-listed-special", action="store_true")
args = parser.parse_args()
if args.count < 1:
parser.error("count must be at least 1")
for address in generate(args.class_name, args.count, args.exclude_listed_special):
print(address)
Run it
- Save the script as
random_ipv4_class.py. - Generate ten Class B samples:
python3 random_ipv4_class.py B. - Generate 25 Class C samples while excluding the ranges in the script:
python3 random_ipv4_class.py C --count 25 --exclude-listed-special. - For multicast samples, use
D; for reserved-range samples, useE. Do not use those outputs as ordinary unicast host addresses.
The generator uses Python’s secrets module for random selection. The selection is not seeded, so rerunning it does not reproduce the same list. It also samples with replacement: duplicates are possible, particularly when requesting a large count or filtering a range. A request for an extremely large count with filtering can take a long time. The script has no network probing and does not allocate or reserve the resulting values.
Rank #2
Understand the filter’s limits
The optional filter is intentionally a finite list, not a claim that every remaining result is globally routable or available. It excludes the three private-use blocks—10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16—identified in RFC 1918, plus several other ranges in the IANA registry. The listed test networks are documentation-only examples; loopback and link-local also have local purposes. Even an address outside those ranges may have other special-purpose status or be unsuitable in your environment. Check the current IANA registry and your network’s routing and assignment rules for real configuration decisions.
Recommended Free Tools
What the generator does—and does not—tell you
- Class match: The first octet falls within the selected historic range. For A, the script uses 1–126 as the ordinary legacy range; B and C use 128–191 and 192–223, while D and E cover their multicast and reserved spans.
- Syntax: Each result is a valid dotted-decimal IPv4 value produced from 32 bits.
- Not a subnet plan: A class does not establish your intended CIDR prefix, subnet boundaries, gateway, network address, or broadcast address. Those depend on the actual prefix and network design.
- Not an ownership or availability check: Random selection cannot tell whether someone has been assigned an address, whether you may use it, or whether a host responds.
- Not a reachability test: The code sends no packets. IANA’s source, destination, forwardable, and globally reachable properties are separate fields, and a special-purpose designation alone does not determine every local use. IANA cautions that special-purpose prefixes are not guaranteed routability in any particular local or global context.
- Not anonymity: Generating an address does not change the IP address your device uses on a connection or conceal your network identity.
Use a CIDR prefix for a real network
If you are configuring a LAN, firewall, cloud network, or route, start with the prefix your environment requires, not a legacy class. A prefix such as 192.168.10.0/24 defines the block size explicitly. Verify that it does not overlap another route or network you must reach, and choose usable host addresses according to the subnet’s rules and your platform’s configuration. The value 192.168.10.0/24 is only an example of notation; do not assume it is available or appropriate for your setup.
Rank #3
- Used Book in Good Condition
Private IPv4 ranges are intended for private internets and are not globally reachable in the IANA registry. Public routing, address assignment, NAT, and local policies require separate consideration. Use your network administrator, provider, or cloud platform’s assigned plan where applicable; a random generator is for samples, test data, and instruction, not for selecting production allocations. The live IANA registry is the useful check for special-purpose categories, while RFC 4632 explains why class labels no longer define modern allocation.
Common problems and fixes
- “Invalid choice” for the class: Enter one uppercase letter from
AthroughE, as shown in the command examples. - The command says Python is missing: Install or use a Python 3 interpreter, then run the script with
python3. On systems where Python 3 is invoked aspython, use that command instead. - The script prints fewer addresses than expected or seems to stall: The optional filter rejects candidates and draws again. Request fewer results, remove
--exclude-listed-specialif broad legacy-range samples are sufficient, or review the explicit exclusions for your use case. - You got a duplicate: Sampling is with replacement. The same address can appear more than once; this output should not be treated as a unique allocation list.
- A generated value does not answer a ping: The script never checks hosts. A timeout may reflect routing, filtering, host state, or other network conditions; it does not make the value a usable address.
- A “public-looking” result is rejected by your network: The old class range does not certify public status or suitability. Check the prefix, assignment, special-use registry, and local routes instead of repeatedly generating values.
Or skip the browser setup
If what you need is a clean screenshot of a webpage displaying your generated sample, ScreenshotNeo can return a capture or PDF through one request. It does not generate or validate IP addresses; use the script above for that. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed; an MCP server lets AI agents take screenshots; and 1,000 screenshots a month are free with no card, with paid plans starting at $5 for 3,000. See the API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
Sign up free for 1,000 screenshots a month, with no card required.
Frequently Asked Questions
Can a random IPv4 address be used as a test value in documentation?
Use one of the documentation ranges, such as 192.0.2.0/24, 198.51.100.0/24, or 203.0.113.0/24, rather than presenting an arbitrary result as an address you own.
Do IPv4 address classes apply to IPv6?
No. The A–E labels in this guide describe historical IPv4 categories; they are not a way to classify IPv6 addresses.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

