Comparison

util/ip.lua @ 5588:8c1a3243d16f

util.ip: Add 'private' method/property to determine whether an IP address is generally expected to be internet-routeable (YMMV)
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 May 2013 14:53:51 +0100
parent 5587:e108c3f97f26
child 5599:34e9f237b915
comparison
equal deleted inserted replaced
5587:e108c3f97f26 5588:8c1a3243d16f
191 end 191 end
192 self.scope = value; 192 self.scope = value;
193 return value; 193 return value;
194 end 194 end
195 195
196 function ip_methods:private()
197 local private = self.scope ~= 0xE;
198 if not private and self.proto == "IPv4" then
199 local ip = self.addr;
200 local fields = {};
201 ip:gsub("([^.]*).?", function (c) fields[#fields + 1] = tonumber(c) end);
202 if fields[1] == 127 or fields[1] == 10 or (fields[1] == 192 and fields[2] == 168)
203 or (fields[1] == 172 and (fields[2] >= 16 or fields[2] <= 32)) then
204 private = true;
205 end
206 end
207 self.private = private;
208 return private;
209 end
210
196 return {new_ip = new_ip, 211 return {new_ip = new_ip,
197 commonPrefixLength = commonPrefixLength}; 212 commonPrefixLength = commonPrefixLength};