From b80bd744ad873f6fc43018bc4bfb90677de167bd Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 17 Dec 2012 12:01:45 +0100 Subject: Start of GS5. --- misc/freeswitch/scripts/common/ipcalc.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 misc/freeswitch/scripts/common/ipcalc.lua (limited to 'misc/freeswitch/scripts/common/ipcalc.lua') diff --git a/misc/freeswitch/scripts/common/ipcalc.lua b/misc/freeswitch/scripts/common/ipcalc.lua new file mode 100644 index 0000000..5c19d20 --- /dev/null +++ b/misc/freeswitch/scripts/common/ipcalc.lua @@ -0,0 +1,27 @@ +-- Gemeinschaft 5 module: ip calculation functions +-- (c) AMOOMA GmbH 2012 +-- + +module(...,package.seeall) + +function ipv4_to_i(ip_address_str) + local octet4, octet3, octet2, octet1 = ip_address_str:match('(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)'); + if octet4 and octet3 and octet2 and octet1 then + return (2^24*octet4 + 2^16*octet3 + 2^8*octet2 + octet1); + end +end + +function ipv4_to_network_netmask(ip_address_str) + local octet4, octet3, octet2, octet1, netmask = ip_address_str:match('(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)/(%d%d?)'); + if octet4 and octet3 and octet2 and octet1 and netmask then + return (2^24*octet4 + 2^16*octet3 + 2^8*octet2 + octet1), tonumber(netmask); + end +end + +function ipv4_network(ip_address, netmask) + return math.floor(ip_address / 2^(32-netmask)); +end + +function ipv4_in_network(ip_address, network, netmask) + return ipv4_network(ip_address, netmask) == ipv4_network(network, netmask); +end -- cgit v1.2.3