summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/VyattaMisc.pm27
1 files changed, 27 insertions, 0 deletions
diff --git a/scripts/VyattaMisc.pm b/scripts/VyattaMisc.pm
index 48b3aa7..abb5fbb 100755
--- a/scripts/VyattaMisc.pm
+++ b/scripts/VyattaMisc.pm
@@ -26,6 +26,11 @@
#
package VyattaMisc;
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT = qw(getNetAddIP isIpAddress);
+@EXPORT_OK = qw(getNetAddIP isIpAddress);
+
use strict;
@@ -60,6 +65,28 @@ sub getNetAddrIP {
return $naip;
}
+sub isIpAddress {
+ my $ip = shift;
+
+ $_ = $ip;
+ if ( ! /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
+ return 0;
+ }
+ else {
+ my @ips = split /\./, $ip;
+ my $octet = 0;
+ my $counter = 0;
+
+ foreach $octet (@ips) {
+ if (($octet < 0) || ($octet > 255)) { return 0; }
+ if (($counter == 0) && ($octet < 1)) { return 0; }
+ $counter++;
+ }
+ }
+
+ return 1;
+}
+
sub isClusterIP {
my ($vc, $ip) = @_;