7 |
7 |
8 local ip_methods = {}; |
8 local ip_methods = {}; |
9 local ip_mt = { __index = function (ip, key) return (ip_methods[key])(ip); end, |
9 local ip_mt = { __index = function (ip, key) return (ip_methods[key])(ip); end, |
10 __tostring = function (ip) return ip.addr; end, |
10 __tostring = function (ip) return ip.addr; end, |
11 __eq = function (ipA, ipB) return ipA.addr == ipB.addr; end}; |
11 __eq = function (ipA, ipB) return ipA.addr == ipB.addr; end}; |
12 local hex2bits = { ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011", ["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111", ["8"] = "1000", ["9"] = "1001", ["A"] = "1010", ["B"] = "1011", ["C"] = "1100", ["D"] = "1101", ["E"] = "1110", ["F"] = "1111" }; |
12 local hex2bits = { |
|
13 ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011", |
|
14 ["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111", |
|
15 ["8"] = "1000", ["9"] = "1001", ["A"] = "1010", ["B"] = "1011", |
|
16 ["C"] = "1100", ["D"] = "1101", ["E"] = "1110", ["F"] = "1111", |
|
17 }; |
13 |
18 |
14 local function new_ip(ipStr, proto) |
19 local function new_ip(ipStr, proto) |
15 if not proto then |
20 if not proto then |
16 local sep = ipStr:match("^%x+(.)"); |
21 local sep = ipStr:match("^%x+(.)"); |
17 if sep == ":" or (not(sep) and ipStr:sub(1,1) == ":") then |
22 if sep == ":" or (not(sep) and ipStr:sub(1,1) == ":") then |