NAME

PDK::Utils::Ip - Utility class for IP address and mask handling

VERSION

Version 1.0

SYNOPSIS

use PDK::Utils::Ip;

my $ip_utils = PDK::Utils::Ip->new();

# Get integer range from IP range
my ($min, $max) = $ip_utils->getRangeFromIpRange('192.168.1.1', '192.168.1.10');

# Get range from IP and mask
my $set = $ip_utils->getRangeFromIpMask('192.168.1.1', 24);

# Get network IP
my $net_ip = $ip_utils->getNetIpFromIpMask('192.168.1.1', 24);

METHODS

getRangeFromIpRange($ipMin, $ipMax)

Get integer range from an IP range.

Parameters:

  • $ipMin - Minimum IP address

  • $ipMax - Maximum IP address

Returns:

Scalar context: PDK::Utils::Set object

List context: (minimum, maximum)

getRangeFromIpMask($ip, $mask)

Get range from IP and mask.

Parameters:

  • $ip - IP address or IP range

  • $mask - Mask (optional, default is 32)

Returns:

Scalar context: PDK::Utils::Set object

List context: (minimum, maximum)

getNetIpFromIpMask($ip, $mask)

Get network IP from IP and mask.

Parameters:

  • $ip - IP address

  • $mask - Mask (optional, default is 32)

Returns:

Network IP address

changeIntToIp($num)

Convert an integer to an IP address.

Parameters:

  • $num - Integer form of IP

Returns:

Dotted-decimal form of IP address

changeIpToInt($ip)

Convert an IP address to an integer.

Parameters:

  • $ip - Dotted-decimal form of IP address

Returns:

Integer form of IP

Exception:

Throws an exception if the IP format is invalid.

changeMaskToNumForm($mask)

Convert a mask to numeric form.

Parameters:

  • $mask - Mask (can be in dotted-decimal or numeric form)

Returns:

Numeric form of mask (0-32)

Exception:

Throws an exception if the mask format is invalid or out of range.

changeWildcardToMaskForm($wildcard)

Convert a wildcard mask to standard mask form.

Parameters:

  • $wildcard - Wildcard mask

Returns:

Mask form, or undef if conversion fails.

changeMaskToIpForm($mask)

Convert a numeric mask to IP form.

Parameters:

  • $mask - Mask (numeric or IP form)

Returns:

IP form of the mask

Exception:

Throws an exception if the mask format is invalid or out of range.

getIpMaskFromRange($min, $max)

Get IP/mask representation from IP range.

Parameters:

  • $min - Minimum IP (integer form)

  • $max - Maximum IP (integer form)

Returns:

IP/mask representation or IP range

Exception:

Throws an exception if $max is undefined.

getRangeFromService($service)

Get range from service description.

Parameters:

  • $service - Service description (format: protocol/port)

Returns:

Scalar context: PDK::Utils::Set object

List context: (minimum, maximum)

AUTHOR

WENWU YAN <968828@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2024 WENWU YAN. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.