is-local-address
v2.3.2
Published
Static check if a hostname is a local IP address.
Readme
is-local-address
Check if an URL hostname is a local address, including support for Bogon IP address ranges.
Why is-local-address?
Most solutions typically determine local IP addresses by checking DNS, which is slow and unreliable. This implementation uses the Bogon IP address specification for static validation, delivering:
- 5x faster than alternative approaches (DNS-based)
- 100x smaller bundle size compared to similar libraries
- 100% accuracy on all RFC-defined private IP ranges
- Zero dependencies for core functionality
- Supports IPv4 and IPv6 including edge cases and mapped addresses
Check the benchmark for detailed performance metrics comparison.
How it works
Instead of performing DNS lookups or complex regex validations, is-local-address uses a static, efficient approach:
- No network calls - Validates against RFC specifications offline
- Pure regex matching - Optimized patterns for IPv4 and IPv6
- Minimal overhead - Only ~100 bytes gzipped
This makes it ideal for:
- High-performance APIs and microservices
- Edge computing environments with limited resources
- Security checks that need to run frequently
- Any scenario where you need fast, reliable local IP detection
Install
$ npm install is-local-address --saveUsage
The method exported by default supports detection of both IPv4 and IPv6 addresses:
const isLocalAddress = require('is-local-address')
isLocalAddress(new URL('https://127.0.0.1').hostname) // true
isLocalAddress(new URL('http://[::]:3000').hostname) // true
isLocalAddress(new URL('https://example.com').hostname) // falseYou can also specify to just resolve IPv4:
const isLocalAddress = require('is-local-address/ipv4')
isLocalAddress(new URL('https://127.0.0.1').hostname) // true
isLocalAddress(new URL('http://[::1]:3000').hostname) // falseor just IPv6:
const isLocalAddress = require('is-local-address/ipv6')
isLocalAddress(new URL('http://[::]:3000').hostname) // true
isLocalAddress(new URL('https://127.0.0.1').hostname) // falseLicense
is-local-address © Kiko Beats, released under the MIT License. Authored and maintained by Kiko Beats with help from contributors.
kikobeats.com · GitHub Kiko Beats · X @Kikobeats
