@untools/ip-url
Version:
Get local IP address and format URLs with it
80 lines (49 loc) • 1.57 kB
Markdown
A simple utility to get the local IP address of your machine and format URLs with it instead of using "localhost".
```bash
npm install -g @untools/ip-url
```
```bash
npm install @untools/ip-url
```
After installing globally, you can use it as follows:
```bash
ip-url
ip-url 8080
ip-url --protocol https
ip-url --family IPv6
ip-url --all
ip-url --help
```
```typescript
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 addresses
```
Returns the primary IP address of the machine.
Returns a formatted URL with the IP address instead of localhost.
Returns an array of all IP addresses on the machine.
MIT