1.0.0 • Published 5 months ago

is-host-local v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

is-host-local

A lightweight utility to check if a hostname resolves to a local IP address.

Installation

npm install is-host-local

Usage

TypeScript

import isHostLocal from 'is-host-local';

async function checkHost() {
  const result = await isHostLocal('localhost');
  console.log(result); // true
  
  const result2 = await isHostLocal('google.com');
  console.log(result2); // false
}

JavaScript

const isHostLocal = require('is-host-local').default;

async function checkHost() {
  const result = await isHostLocal('localhost');
  console.log(result); // true
  
  const result2 = await isHostLocal('google.com');
  console.log(result2); // false
}

Return Values

  • true: The hostname resolves to a local IP address (127.0.0.1 or private IP ranges)
  • false: The hostname resolves to a public IP address
  • null: An error occurred while checking the hostname

License

MIT