Sort IP Addresses

Sorts IPv4 addresses the right way, part by part, so 10.0.0.2 comes before 10.0.0.10. Also removes duplicates.

Advertisement

Why a normal sort gets it wrong

A plain text sort compares character by character, so 10.0.0.10 lands before 10.0.0.2 and 100.1.1.1 before 20.1.1.1. This sort reads each number between the dots as a number.

Good for

  • Blocklists and allowlists for .htaccess, nginx, firewalls and fail2ban
  • IPs pulled from access logs. Use Count duplicates to see which addresses appear most often
  • Inventory and DHCP reservation lists

Lines with extra text, like Deny from 10.0.0.2, sort correctly as long as they all start the same way. CIDR ranges like /24 sort with their base address. IPv6 addresses are sorted as text.

A blocklist

Before
192.168.1.20
10.0.0.10
192.168.1.3
10.0.0.2
8.8.8.8
192.168.1.3
172.16.0.0/12
After
8.8.8.8
10.0.0.2
10.0.0.10
172.16.0.0/12
192.168.1.3
192.168.1.20

Questions

Does it validate IP addresses?

No. It sorts whatever you paste. Invalid entries just sort alongside the rest.

Are my IP lists sent anywhere?

No. Sorting happens entirely in your browser.