openresty-IP字符串转数字
2016-06-28 11:44
357 查看
1. IP字符串转换成数字
local str = "127.0.0.1" local o1,o2,o3,o4 = str:match("(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)" ) -- local o1,o2,o3,o4 = str:match("(%d+)%.(%d+)%.(%d+)%.(%d+)") local num = 2^24*o1 + 2^16*o2 + 2^8*o3 + o4
2. 数字转IP字符串
todo
3. 用SQL更方便
mysql> SELECT INET_ATON('209.207.224.40'); +-----------------------------+ | INET_ATON('209.207.224.40') | +-----------------------------+ | 3520061480 | +-----------------------------+ 1 row in set (0.00 sec) mysql> SELECT INET_NTOA(3520061480); +-----------------------+ | INET_NTOA(3520061480) | +-----------------------+ | 209.207.224.40 | +-----------------------+ 1 row in set (0.00 sec) mysql>
ref
http://stackoverflow.com/questions/8200228/how-can-i-convert-an-ip-address-into-an-integer-with-lua相关文章推荐
- openresty中使用lua-nginx创建socket实例
- Mac系统的openresty编译安装
- 如何集成varnish到已有的网站架构
- 使用Nginx+Lua进行Web开发
- ubuntu14.04安装OpenResty
- Openresty + MySQL + Redis 安装篇
- Nginx-openresty+mysql+redis使用篇(一)
- OpenResty学习开端
- OpenResty学习笔记(一)数据结构与控制流
- OpenResty学习笔记(五) table库
- [openresty]安装nginx_lua
- openresty+websocket+redis simple chat
- openresty--基于redis实现一个动态路由
- openresty--centos7下开发环境安装
- [openresty] hello world
- openresty简记
- centos+openresty+mariaDB+php搭建web服务器
- 编译安装openresty+mysql+php7