zoukankan      html  css  js  c++  java
  • LUA中获得服务器IP

    local t = {}
    -- 引入相关包local socket = require("socket")
    
    function t.main()
    
            local a,b=pcall(t.execute);
            if a==false then
                    logerror(a,b);
            end
    
    end
    
    function t.execute()
            logdebug("start");
            --local m = os.execute("ifconfig");
            --logdebug(m);
            --local s= io.popen('ifconfig')
            --local b = s:read("*all")
            --logdebug(b);
            --local t=os.execute(ip addr|grep inet|grep -v inet6|grep eth0|awk '{print $2}'|awk -F "/" '{print $1}' >> /log/app/localhost.tmp);
            --local t=os.execute("ifconfig eth0 |grep 'inet addr'| cut -f 2 -d ':'|cut -f 1 -d ' ' >> /log/app/localhost.tmp ");
            logdebug(os.time());
            local ip,resolved = socket.dns.toip(socket.dns.gethostname());
            logdebug(ip);
            logdebug(resolved);
            logdebug(t.GetAdd(socket.dns.gethostname()));
    end
    function t.GetAdd(hostname)
        local ip, resolved = socket.dns.toip(hostname)
        local ListTab = {}
        for k, v in ipairs(resolved.ip) do
            logdebug(k.."|"..v);
            table.insert(ListTab, v)
        end
        return ListTab
    end
    
    return t
  • 相关阅读:
    进程与线程的区别
    开启线程的两种方式
    线程
    生产者消费者模型(重要)
    队列
    互斥锁
    守护进程(了解)
    Process对象的其它方法与属性(join)
    僵尸进程与孤儿进程
    Servlet
  • 原文地址:https://www.cnblogs.com/sagech/p/9454950.html
Copyright © 2011-2022 走看看