@@ -1455,9 +1455,17 @@ added: v0.3.0
1455
1455
* ` input ` {string}
1456
1456
* Returns: {integer}
1457
1457
1458
- Tests if input is an IP address. Returns ` 0 ` for invalid strings,
1459
- returns ` 4 ` for IP version 4 addresses, and returns ` 6 ` for IP version 6
1460
- addresses.
1458
+ Returns ` 6 ` if ` input ` is an IPv6 address. Returns ` 4 ` if ` input ` is an IPv4
1459
+ address in [ dot-decimal notation] [ ] with no leading zeroes. Otherwise, returns
1460
+ ` 0 ` .
1461
+
1462
+ ``` js
1463
+ net .isIP (' ::1' ); // returns 6
1464
+ net .isIP (' 127.0.0.1' ); // returns 4
1465
+ net .isIP (' 127.000.000.001' ); // returns 0
1466
+ net .isIP (' 127.0.0.1/24' ); // returns 0
1467
+ net .isIP (' fhqwhgads' ); // returns 0
1468
+ ```
1461
1469
1462
1470
## ` net.isIPv4(input) `
1463
1471
@@ -1468,7 +1476,15 @@ added: v0.3.0
1468
1476
* ` input ` {string}
1469
1477
* Returns: {boolean}
1470
1478
1471
- Returns ` true ` if input is a version 4 IP address, otherwise returns ` false ` .
1479
+ Returns ` true ` if ` input ` is an IPv4 address in [ dot-decimal notation] [ ] with no
1480
+ leading zeroes. Otherwise, returns ` false ` .
1481
+
1482
+ ``` js
1483
+ net .isIPv4 (' 127.0.0.1' ); // returns true
1484
+ net .isIPv4 (' 127.000.000.001' ); // returns false
1485
+ net .isIPv4 (' 127.0.0.1/24' ); // returns false
1486
+ net .isIPv4 (' fhqwhgads' ); // returns false
1487
+ ```
1472
1488
1473
1489
## ` net.isIPv6(input) `
1474
1490
@@ -1479,7 +1495,12 @@ added: v0.3.0
1479
1495
* ` input ` {string}
1480
1496
* Returns: {boolean}
1481
1497
1482
- Returns ` true ` if input is a version 6 IP address, otherwise returns ` false ` .
1498
+ Returns ` true ` if ` input ` is an IPv6 address. Otherwise, returns ` false ` .
1499
+
1500
+ ``` js
1501
+ net .isIPv6 (' ::1' ); // returns true
1502
+ net .isIPv6 (' fhqwhgads' ); // returns false
1503
+ ```
1483
1504
1484
1505
[ IPC ] : #ipc-support
1485
1506
[ Identifying paths for IPC connections ] : #identifying-paths-for-ipc-connections
@@ -1533,6 +1554,7 @@ Returns `true` if input is a version 6 IP address, otherwise returns `false`.
1533
1554
[ `writable.destroyed` ] : stream.md#writabledestroyed
1534
1555
[ `writable.end()` ] : stream.md#writableendchunk-encoding-callback
1535
1556
[ `writable.writableLength` ] : stream.md#writablewritablelength
1557
+ [ dot-decimal notation ] : https://en.wikipedia.org/wiki/Dot-decimal_notation
1536
1558
[ half-closed ] : https://tools.ietf.org/html/rfc1122
1537
1559
[ stream_writable_write ] : stream.md#writablewritechunk-encoding-callback
1538
1560
[ unspecified IPv4 address ] : https://en.wikipedia.org/wiki/0.0.0.0
0 commit comments