summaryrefslogtreecommitdiffstats
path: root/abs/not_built/core/tweaker/bin/LocalIPCheck.pl
diff options
context:
space:
mode:
Diffstat (limited to 'abs/not_built/core/tweaker/bin/LocalIPCheck.pl')
-rwxr-xr-xabs/not_built/core/tweaker/bin/LocalIPCheck.pl47
1 files changed, 47 insertions, 0 deletions
diff --git a/abs/not_built/core/tweaker/bin/LocalIPCheck.pl b/abs/not_built/core/tweaker/bin/LocalIPCheck.pl
new file mode 100755
index 0000000..b744fb6
--- /dev/null
+++ b/abs/not_built/core/tweaker/bin/LocalIPCheck.pl
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+
+# Valid private IP ranges
+
+my @LOCAL_IP_RANGES = ("10.0.0.0", "10.255.255.255",
+ "172.16.0.0", "172.31.255.255",
+ "192.168.0.0", "192.168.255.255");
+
+# input: A dotted quad IP address.
+
+# output: 0 if a public (internet) address
+# : 8 if a class A private (LAN) address
+# : 12 if a class B private (LAN) address
+# : 16 if a class C private (LAN) address
+
+sub get_IP_number () {
+ my ($dotted_quad) = @_;
+ my $IP_number=0;
+
+ split(/\./, $dotted_quad);
+
+ for (my $i=0; $i < 4; $i++) {
+ $IP_number=$IP_number+@_[3-$i]*(2**(8*$i));
+ }
+ return $IP_number;
+}
+
+while(<>) {
+ chop;
+ my $IPnumber=&get_IP_number($_);
+ my $class=16;
+
+ while (@LOCAL_IP_RANGES) {
+ my $highIPnumber = &get_IP_number(pop(@LOCAL_IP_RANGES));
+ my $lowIPnumber = &get_IP_number(pop(@LOCAL_IP_RANGES));
+
+ if (($lowIPnumber <= $IPnumber) && ($highIPnumber >= $IPnumber)) {
+ exit($class); # PRIVATE IP
+ } else {
+ $class += 4;
+ }
+ }
+}
+
+exit(0); # PUBLIC IP
+
+