Static check if a hostname is a local IP address.
npm install is-local-address> Check if an URL hostname is a local address, including support for Bogon IP address ranges.
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.
Instead of performing DNS lookups or complex regex validations, is-local-address uses a static, efficient approach:
1. No network calls - Validates against RFC specifications offline
2. Pure regex matching - Optimized patterns for IPv4 and IPv6
3. 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
``bash`
$ npm install is-local-address --save
The method exported by default supports detection of both IPv4 and IPv6 addresses:
`js
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) // false
`
You can also specify to just resolve IPv4:
`js`
const isLocalAddress = require('is-local-address/ipv4')
isLocalAddress(new URL('https://127.0.0.1').hostname) // true
isLocalAddress(new URL('http://[::1]:3000').hostname) // false
or just IPv6:
`js``
const isLocalAddress = require('is-local-address/ipv6')
isLocalAddress(new URL('http://[::]:3000').hostname) // true
isLocalAddress(new URL('https://127.0.0.1').hostname) // false
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