@untools/ip-url
v0.1.1
Published
Get local IP address and format URLs with it
Downloads
34
Maintainers
Readme
@untools/ip-url
A simple utility to get the local IP address of your machine and format URLs with it instead of using "localhost".
Installation
Global Installation
npm install -g @untools/ip-urlLocal Installation
npm install @untools/ip-urlUsage
As a CLI Tool
After installing globally, you can use it as follows:
# Get the default URL (http://your-ip:3000)
ip-url
# Specify a port
ip-url 8080
# Use HTTPS
ip-url --protocol https
# Use IPv6
ip-url --family IPv6
# Show all available IP addresses
ip-url --all
# Get help
ip-url --helpAs a Library
import { getPrimaryIP, formatIPUrl, getLocalIPs } from '@untools/ip-url';
// Get the primary IP address
const ip = getPrimaryIP(); // Returns something like '192.168.1.5'
// Format a URL with the IP address
const url = formatIPUrl(3000); // Returns 'http://192.168.1.5:3000'
// Custom protocol and port
const httpsUrl = formatIPUrl(8080, 'https'); // Returns 'https://192.168.1.5:8080'
// Get all IP addresses
const allIPs = getLocalIPs(); // Returns an array of IP addressesAPI
getPrimaryIP(family?: 'IPv4' | 'IPv6'): string | undefined
Returns the primary IP address of the machine.
formatIPUrl(port: number, protocol?: 'http' | 'https', family?: 'IPv4' | 'IPv6'): string | undefined
Returns a formatted URL with the IP address instead of localhost.
getLocalIPs(family?: 'IPv4' | 'IPv6', skipInternal?: boolean): string[]
Returns an array of all IP addresses on the machine.
License
MIT
