add two missing functions to ip (subnet, cidrSubnet)

This commit is contained in:
xinkai 2015-02-01 12:32:26 +08:00
parent 7bab855ae3
commit 4e752c7705
2 changed files with 27 additions and 1 deletions

View File

@ -16,4 +16,6 @@ ip.mask("192.168.0.1", "255.255.255.0");
ip.not("255.255.255.0");
ip.or("192.168.0.1", "255.255.255.0");
var buff:any = ip.toBuffer(myIP);
ip.toString(buff);
ip.toString(buff);
ip.subnet('192.168.1.134', '255.255.255.192');
ip.cidrSubnet('192.168.1.134/26');

24
ip/ip.d.ts vendored
View File

@ -5,6 +5,17 @@
interface NodeBuffer { }
interface SubnetInfo {
networkAddress: string;
firstAddress: string;
lastAddress: string;
broadcastAddress: string;
subnetMask: string;
subnetMaskLength: number;
numHosts: number;
length: number;
}
declare module "ip" {
/**
* Check two IP address are the same.
@ -88,4 +99,17 @@ declare module "ip" {
* Convert an IPv4 IP address from its the long numeric value to a string.
**/
export function fromLong(ip: number): string;
/**
* Get the subnet information.
* @param ip IP address.
* @param subnet Subnet address.
*/
export function subnet(ip: string, subnet: string): SubnetInfo;
/**
* Get the subnet information.
* @param cidr CIDR address.
*/
export function cidrSubnet(cidr: string): SubnetInfo;
}